-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
executable file
·43 lines (36 loc) · 1.46 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
var storage = chrome.storage.sync;
var storedSitesArray;
var siteStorageKey="sites";
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if(changeInfo.status === 'complete'){
storage.get(siteStorageKey,function(result) {
storedSitesArray = result[siteStorageKey] ? result[siteStorageKey] : [];
for ( var i = 0; i < storedSitesArray.length; i++) {
if (tab.url == storedSitesArray[i][1]) {
var c = 0;
var max = 40;
var foundUrl = false;
var interval = setInterval(function() {
c++;
chrome.tabs.sendMessage(tab.id, {command: "getNext", tabId:tab.id}, function(response) {
if (response.nextUrl) {
clearInterval(interval);
foundUrl = true;
if (tab.url != response.nextUrl) {
updateTab(response.refreshTab, response.nextUrl);
}
}
});
if (c > max || foundUrl) {
clearInterval(interval);
}
}, 200);
break;
}
}
});
}
});
function updateTab(id, nextUrl) {
chrome.tabs.update(id,{ url : nextUrl });
}