-
Notifications
You must be signed in to change notification settings - Fork 326
/
Copy pathbg2.js
28 lines (27 loc) · 1 KB
/
bg2.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
const submissions = [];
const listener = (details) => {
const submission_id = details.url.split("_")[1];
const token = details.requestHeaders[2].value;
if (!submissions.includes({})) {
const obj = { submission_id, token }
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
const idx = submissions.findIndex(submission_id);
submissions[idx] = { submission_id, ...request.entry };
})
}
}
function checkResult(item) {
fetch(`https://www.codechef.com/api/ide/submit?solution_id=item["submission_id"]`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-csrf-token": item.token
}
}).then(res => res.json()).then(data => {
if (res.result_code != "wait") {
}
})
}
chrome.webRequest.onBeforeSendHeaders.addListener(listener, {
urls: ["https://www.codechef.com/api/ide/submit?solution_id=*"]
}, ["requestHeaders"])