-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
39 lines (37 loc) · 1.06 KB
/
background.js
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
chrome.runtime.onInstalled.addListener(() => {
chrome.action.openPopup();
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === "fetchDiff") {
fetch(message.url)
.then((response) => response.text())
.then((diffText) => {
sendResponse({ success: true, data: diffText });
})
.catch((error) => {
console.error("Failed to fetch diff:", error);
sendResponse({ success: false });
});
return true;
} else if (message.type === "openChatGPT") {
chrome.storage.local.set({ copiedText: message.data }, () => {
chrome.tabs.create({
url: "https://chatgpt.com/g/g-jYKKhgJny-code-review-based-by-git-diff",
});
});
}
});
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (
changeInfo.status === "complete" &&
tab.url &&
tab.url.includes("chatgpt.com")
) {
setTimeout(() => {
chrome.scripting.executeScript({
target: { tabId: tabId },
files: ["chatgpt_injector.js"],
});
}, 1000);
}
});