-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
48 lines (47 loc) · 1.66 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
40
41
42
43
44
45
46
47
48
chrome.runtime.onMessage.addListener();
// triggering a reveal requires two network requests in succession
// the first is a problem/submit, the second is a graphql request
// which fetches the next suggested problems. If these requests happen
// within 15 seconds of each other, it's a solve
chrome.webRequest.onCompleted.addListener(
({ url }) => {
chrome.storage.local.get(
['hidelcReveal', 'hidelcActive'],
({ hidelcReveal, hidelcActive }) => {
// if the extension and feature are active
if (hidelcReveal && hidelcActive) {
if (
url.includes('https://leetcode.com/problems/') &&
url.includes('/submit/')
) {
chrome.storage.local.set({ hidelcSubmitted: true });
// disables the reveal if no graphql request is made in 15 seconds
setTimeout(
() => chrome.storage.local.set({ hidelcSubmitted: false }),
1000 * 15,
);
} else if (url === 'https://leetcode.com/graphql') {
chrome.storage.local.get(
['hidelcSubmitted'],
({ hidelcSubmitted }) => {
// disables the reveal if no problem/submit request has been made in the last 15 seconds
if (!hidelcSubmitted) return;
chrome.tabs.query({ active: true }, tabs => {
chrome.tabs.sendMessage(tabs[0].id, {
hidelcRevealEvent: true,
});
});
},
);
}
}
},
);
},
{
urls: [
'https://leetcode.com/graphql',
'https://leetcode.com/problems/*/submit/',
],
},
);