-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
32 lines (28 loc) · 891 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
const second = 1000;
const variate = second * 10;
function httpGetAsync(url, callback) {
let xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = () => {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open('GET', url, true);
xmlHttp.send(null);
}
function trySendRequestLoop() {
let time = second * 50 + Math.floor(Math.random() * variate);
chrome.tabs.query({
}, (tabs) => {
for (let tab of tabs) {
let url = tab.url;
if (url.includes('vaje.um.si') || url.includes('vaje.uni-mb.si')) {
httpGetAsync('https://vaje.um.si/vaje/new/vaje.jsp', (data) => console.log('ping send!'));
return;
}
}
console.log('vaje uni not found in tabs!');
});
console.log(`resending in ${time / 1000} seconds!`);
setTimeout(trySendRequestLoop, time);
}
trySendRequestLoop();