1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 12:50:36 +01:00

More flexible list checking

This commit is contained in:
kkapsner 2014-10-11 00:07:51 +02:00
parent 147a2893c4
commit 3c96a9e3f5

View File

@ -71,59 +71,63 @@
preferences.on("blackList", function(){ preferences.on("blackList", function(){
updateBlackList(); updateBlackList();
}); });
function checkURL(url){
var url = new URL(url);
var mode = "block";
switch (prefs.blockMode){
case "blockEverything":
mode = "block";
break;
case "allowOnlyWhiteList":
if (whiteList.match(url)){
mode = "unblock";
}
else {
mode = "block";
}
break;
case "ask":
if (whiteList.match(url)){
mode = "unblock";
}
else if (blackList.match(url)){
mode = "block";
}
else {
mode = "ask";
}
break;
case "blockReadout":
if (whiteList.match(url)){
mode = "unblock";
}
else if (blackList.match(url)){
mode = "block";
}
else {
mode = "blockReadout";
}
break;
case "blockOnlyBlackList":
if (blackList.match(url)){
mode = "block";
}
else {
mode = "unblock";
}
break;
case "allowEverything":
mode = "unblock";
break;
default:
console.log("Unknown blocking mode. Default to block everything.");
}
return mode;
}
function checkWorker(worker){ function checkWorker(worker){
try { try {
var url = new URL(worker.url); var mode = checkURL(worker.url);
var mode = "block";
switch (prefs.blockMode){
case "blockEverything":
mode = "block";
break;
case "allowOnlyWhiteList":
if (whiteList.match(url)){
mode = "unblock";
}
else {
mode = "block";
}
break;
case "ask":
if (whiteList.match(url)){
mode = "unblock";
}
else if (blackList.match(url)){
mode = "block";
}
else {
mode = "ask";
}
break;
case "blockReadout":
if (whiteList.match(url)){
mode = "unblock";
}
else if (blackList.match(url)){
mode = "block";
}
else {
mode = "blockReadout";
}
break;
case "blockOnlyBlackList":
if (blackList.match(url)){
mode = "block";
}
else {
mode = "unblock";
}
break;
case "allowEverything":
mode = "unblock";
break;
default:
console.log("Unknown blocking mode. Default to block everything.");
}
worker.port.emit(mode, false, prefs.askOnlyOnce); worker.port.emit(mode, false, prefs.askOnlyOnce);
} }
catch (e){ catch (e){