-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
38 lines (33 loc) · 1013 Bytes
/
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
'use strict';
let intervalId;
const STAT_HAT_API_TIMEOUT = 30000; // IN ms
const RELOAD_WINDOW_TIMEOUT = 60000; // IN ms
function reloadWindow(windowId, options = {}) {
chrome.tabs.query({ windowId: windowId }, async (tabs) => {
const strategy = {};
for (const i in tabs) {
const tab = tabs[i];
chrome.tabs.reload(tab.id, () => {
setTimeout(async () => {
chrome.storage.local.set({
countryCode: options.countryCode
}, function () {
chrome.tabs.executeScript(tab.id, {
file: "stat-hat-executor.js"
})
});
}, STAT_HAT_API_TIMEOUT);
});
}
});
}
chrome.extension.onRequest.addListener((request, sender, sendResponse) => {
if (!request.startInterval) {
clearInterval(intervalId);
//removeTimeoutInjectedScript();
return;
}
intervalId = setInterval(() => {
reloadWindow(request.windowId, { countryCode: request.countryCode });
}, RELOAD_WINDOW_TIMEOUT);
});