mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 04:26:35 +02:00
Added black list and ask.
This commit is contained in:
parent
0ab4f1b7d3
commit
ebe1d66ad5
4 changed files with 113 additions and 15 deletions
78
lib/main.js
78
lib/main.js
|
@ -1,18 +1,44 @@
|
|||
function getDomainRegExpList(domainList){
|
||||
return domainList
|
||||
.split(",")
|
||||
.map(function(entry){
|
||||
return entry.replace(/^\s+|\s+$/g, "");
|
||||
})
|
||||
.filter(function(entry){
|
||||
return !!entry.length;
|
||||
})
|
||||
.map(function(entry){
|
||||
return new RegExp("(?:^|\\.)" + entry.replace(/([\\\+\*\?\[\^\]\$\(\)\{\}\=\!\|\.])/g, "\\$1") + "\\.?$", "i");
|
||||
});
|
||||
}
|
||||
|
||||
var self = require("sdk/self");
|
||||
var pageMod = require("sdk/page-mod");
|
||||
var preferences = require("sdk/simple-prefs");
|
||||
var prefs = preferences.prefs;
|
||||
var {URL} = require("sdk/url");
|
||||
var workers = [];
|
||||
|
||||
var whiteList;
|
||||
updateWhiteList();
|
||||
|
||||
function updateWhiteList(){
|
||||
whiteList = prefs.whiteList.split(",").map(function(entry){
|
||||
return new RegExp("(?:^|\\.)" + entry.replace(/([\\\+\*\?\[\^\]\$\(\)\{\}\=\!\|\.])/g, "\\$1") + "\\.?$", "i");
|
||||
});
|
||||
whiteList = getDomainRegExpList(prefs.whiteList);
|
||||
}
|
||||
updateWhiteList();
|
||||
preferences.on("whiteList", function(){
|
||||
updateWhiteList();
|
||||
workers.forEach(checkWorker);
|
||||
});
|
||||
|
||||
var blackList;
|
||||
function updateBlackList(){
|
||||
blackList = getDomainRegExpList(prefs.blackList);
|
||||
}
|
||||
updateBlackList();
|
||||
preferences.on("blackList", function(){
|
||||
updateBackList();
|
||||
workers.forEach(checkWorker);
|
||||
});
|
||||
|
||||
var workers = [];
|
||||
function detachWorker(worker, workerArray) {
|
||||
var index = workerArray.indexOf(worker);
|
||||
if (index != -1){
|
||||
|
@ -20,22 +46,46 @@ function detachWorker(worker, workerArray) {
|
|||
}
|
||||
}
|
||||
function checkWorker(worker){
|
||||
var url = new URL(worker.url);
|
||||
if (prefs.blockAll || !whiteList.some(function(entry){
|
||||
return url.hostname.match(entry);
|
||||
})){
|
||||
if (prefs.blockAll){
|
||||
worker.port.emit("block");
|
||||
}
|
||||
else {
|
||||
worker.port.emit("unblock");
|
||||
var url = new URL(worker.url);
|
||||
var inBlackList = blackList.some(function(entry){
|
||||
return url.hostname.match(entry);
|
||||
});
|
||||
if (inBlackList){
|
||||
worker.port.emit("block");
|
||||
}
|
||||
else {
|
||||
var inWhiteList = whiteList.some(function(entry){
|
||||
return url.hostname.match(entry);
|
||||
});
|
||||
if (inWhiteList){
|
||||
worker.port.emit("unblock");
|
||||
}
|
||||
else {
|
||||
if (prefs.askPermission){
|
||||
worker.port.emit("ask");
|
||||
}
|
||||
else {
|
||||
worker.port.emit("block");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
preferences.on("whiteList", function(){
|
||||
updateWhiteList();
|
||||
preferences.on("blockAll", function(){
|
||||
if (prefs.blockAll){
|
||||
prefs.askPermission = false;
|
||||
}
|
||||
workers.forEach(checkWorker);
|
||||
});
|
||||
preferences.on("blockAll", function(){
|
||||
preferences.on("askPermission", function(){
|
||||
if (prefs.askPermission){
|
||||
prefs.blockAll = false;
|
||||
}
|
||||
workers.forEach(checkWorker);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue