-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
61 lines (53 loc) · 1.96 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
49
50
51
52
53
54
55
56
57
58
59
60
61
function getPatterns(storedPatterns) {
return [];
}
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
chrome.pageAction.show(tabId);
if (changeInfo.status === "complete") {
chrome.storage.sync.get(['isPaused', 'disableExactMatch', 'urlPatterns'], function(data) {
console.log(data);
if (data.isPaused) {
return;
}
console.log(tab.url);
queryUrl = [];
if (!data.disableExactMatch) {
queryUrl.push(tab.url);
}
queryUrl = queryUrl.concat(getPatterns(data.urlPatterns));
console.log(queryUrl);
if (queryUrl.length === 0) {
return;
}
chrome.tabs.query({url: queryUrl}, function(tabs) {
tabsToRemove = [];
for (t of tabs) {
if (tab.id !== t.id) {
tabsToRemove.push(t.id);
}
}
if (tabsToRemove.length === 0) {
return;
}
console.log("about to delete following tabs");
console.log(tabsToRemove);
chrome.tabs.remove(tabsToRemove, function() {
chrome.storage.sync.get('tabsRemoved', function(item) {
console.log("item");
console.log(item);
count = item.tabsRemoved || 0;
chrome.storage.sync.set({
tabsRemoved: count + tabsToRemove.length
}, function() {
console.log("success!");
console.log(count + tabsToRemove.length);
});
});
});
});
});
}
});
chrome.tabs.onActivated.addListener(function(tabId, changeInfo, tab) {
chrome.pageAction.show(tabId);
});