-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
36 lines (33 loc) · 1.35 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
console.log("Background script running");
chrome.webRequest.onCompleted.addListener(
function(details) {
// console.log("Request completed:", details);
// Inject the content script
if (details.url === "https://chat.openai.com/backend-api/conversation") {
console.log(details)
chrome.tabs.executeScript(details.tabId, {file: 'content.js'});
}
// console.log(details.url);
},
// filters
{
urls: ["https://chat.openai.com/backend-api/conversation*"]
}
);
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if (details.method === "POST" && details.requestBody && details.requestBody.raw && details.url === "https://chat.openai.com/backend-api/conversation/message_feedback") {
// console.log("Request intercepted:", details);
var postedString = decodeURIComponent(String.fromCharCode.apply(null, new Uint8Array(details.requestBody.raw[0].bytes)));
var postedObject = JSON.parse(postedString);
// console.log(postedObject);
chrome.tabs.sendMessage(details.tabId, {action: postedObject.rating, message_id: postedObject.message_id});
}
},
// filters
{
urls: ["https://chat.openai.com/backend-api/conversation*"],
types: ["xmlhttprequest"]
},
["requestBody"]
);