-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
64 lines (60 loc) · 2.91 KB
/
Copy pathbackground.js
File metadata and controls
64 lines (60 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// background.js - Chat Queue for z.ai, Claude, ChatGPT & Copilot
const SUPPORTED_HOSTS = [
"space.chatglm.site", "z.ai",
"chat.openai.com", "chatgpt.com",
"claude.ai",
"copilot.microsoft.com",
"chat.deepseek.com", "deepseek.com",
"qwen.ai",
"gemini.google.com",
"aistudio.google.com"
];
function isSupportedHost(hostname) {
return SUPPORTED_HOSTS.some(h => hostname.includes(h));
}
chrome.commands.onCommand.addListener(async (command) => {
console.log("CQ: Command received:", command);
const [tab] = await chrome.tabs.query({ active: true, lastFocusedWindow: true });
if (!tab || !tab.id) return;
try {
const url = new URL(tab.url || "");
if (!isSupportedHost(url.hostname)) return;
if (command === "toggle-queue") {
chrome.tabs.sendMessage(tab.id, { type: "cq-toggle" }, () => {
if (chrome.runtime.lastError) console.log("CQ: Shortcut error", chrome.runtime.lastError.message);
});
}
} catch (e) { console.log("CQ: Command handler error", e); }
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === "get-current-tab") {
chrome.tabs.query({ active: true, lastFocusedWindow: true }, (tabs) => {
if (tabs[0]) {
const url = new URL(tabs[0].url || "");
const isSup = isSupportedHost(url.hostname);
let site = "none";
if (url.hostname.includes("space.chatglm.site") || url.hostname.includes("z.ai")) site = "zai";
else if (url.hostname.includes("chat.openai.com") || url.hostname.includes("chatgpt.com")) site = "chatgpt";
else if (url.hostname.includes("claude.ai")) site = "claude";
else if (url.hostname.includes("copilot.microsoft.com")) site = "copilot";
else if (url.hostname.includes("deepseek.com")) site = "deepseek";
else if (url.hostname.includes("qwen.ai")) site = "qwen";
else if (url.hostname.includes("gemini.google.com")) site = "gemini";
else if (url.hostname.includes("aistudio.google.com")) site = "aistudio";
sendResponse({ isSupported: isSup, site, url: tabs[0].url, title: tabs[0].title });
} else { sendResponse({ isSupported: false, site: "none" }); }
});
return true;
}
if (message.type === "send-to-content") {
chrome.tabs.query({ active: true, lastFocusedWindow: true }, (tabs) => {
if (tabs[0] && tabs[0].id) {
chrome.tabs.sendMessage(tabs[0].id, message.data, (response) => {
if (chrome.runtime.lastError) console.log("CQ: Send error", chrome.runtime.lastError.message);
sendResponse({ sent: true, response });
});
} else { sendResponse({ sent: false, error: "No active tab" }); }
});
return true;
}
});