-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
38 lines (30 loc) · 979 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
37
38
(function(){
var auxLastUpdate = 0;
// check if the site on the given tab has to be labeled
function labeler(tab){
var title = tab.title;
var url = tab.url;
var l, regexp;
chrome.storage.sync.get(null, function(data){
for ( var i in data.labels ) {
l = data.labels[i];
regexp = new RegExp(l.regexp);
if ( l.enabled && regexp.test(url) ) {
chrome.tabs.sendMessage(tab.id, {'action': 'dolabel', 'data': {'label': l}}, function(response) {
if ( typeof response == 'undefined' ) {
chrome.tabs.executeScript(tab.id, {file: "content/content_script.js"}, function(){
chrome.tabs.insertCSS(tab.id, {file: "content/content_script.css"}, function(){
chrome.tabs.sendMessage(tab.id, {'action': 'dolabel', 'data': {'label': l}}, function(response) {});
});
});
}
});
break;
}
};
});
};
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab){
labeler(tab);
});
})();