-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
37 lines (31 loc) · 1.41 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
//setup message handler for requests coming from popup (toolbar button) and content_scripts
chrome.runtime.onMessage.addListener(messageHandler);
function checkTab(info){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var res = getStatus(tabs[0].url);
if(res.msg=="grey"){
var nFraud=res.nFraud;
if(isNaN(nFraud)) //sanitize
nFraud='error';
if(nFraud>0){
chrome.browserAction.setBadgeText({tabId: tabs[0].tabId, text: nFraud});
chrome.browserAction.setBadgeBackgroundColor({tabId: tabs[0].tabId, color: "#cc0000"});
}
}
else
chrome.browserAction.setBadgeText({tabId: tabs[0].tabId, text: ""});
});
}
//setup handler to update browser action's badge text
chrome.tabs.onActivated.addListener(checkTab);
chrome.tabs.onUpdated.addListener(checkTab);
//setup handler to block black-listed sites
function onBeforeRequest(request){
if(getStatus(request.url).msg=="black") //----------BLOCK-IT----------
// Redirect the browser to the "placeholder" blocked-page
// Furthermore, add the blocked URL to the end of the URL so we can retrieve
// it later, in the case the user wants to ignore the block
return {redirectUrl: chrome.extension.getURL('web/black.html?'+encodeURIComponent(request.url))};
}
chrome.webRequest.onBeforeRequest.addListener(onBeforeRequest, {urls: ["<all_urls>"]}, ["blocking"]);
storage.get(null,init);