1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 12:36:37 +02:00

Version 0.2.0

Reenabled notifications
Code cleanup.
This commit is contained in:
kkapsner 2015-09-06 15:40:34 +02:00
parent 97e0c6b9cd
commit c10b382c93
7 changed files with 106 additions and 83 deletions

View file

@ -20,51 +20,11 @@ var _ = function(name, replace){
return str;
};
function getDomainRegExpList(domainList){
"use strict";
var list = domainList
.split(",")
.map(function(entry){
return entry.replace(/^\s+|\s+$/g, "");
})
.filter(function(entry){
return !!entry.length;
})
.map(function(entry){
var regExp;
var domain = !!entry.match(/^[\w.]+$/);
if (domain){
regExp = new RegExp("(?:^|\\.)" + entry.replace(/([\\\+\*\?\[\^\]\$\(\)\{\}\=\!\|\.])/g, "\\$1") + "\\.?$", "i");
}
else {
regExp = new RegExp(entry, "i");
}
return {
match: function(url){
if (domain){
return url.hostname.match(regExp);
}
else {
return url.href.match(regExp);
}
}
};
});
list.match = function(url){
return this.some(function(entry){
return entry.match(url);
});
};
return list;
}
function checkURL(url, blockMode){
"use strict";
if (url.protocol === "about:") {
return "unblock";
if (url.protocol === "about:" || url.protocol == "chrome:") {
return "allow";
}
var mode = "block";
@ -72,9 +32,17 @@ function checkURL(url, blockMode){
case "blockEverything":
mode = "block";
break;
case "block":
case "blockContext":
case "blockReadout":
case "fake":
case "fakeContext":
case "fakeReadout":
case "allow":
case "allowContext":
case "allowReadout":
if (url && lists.get("white").match(url)){
mode = "unblock";
mode = "allow";
}
else if (url && lists.get("black").match(url)){
mode = "block";
@ -84,7 +52,7 @@ function checkURL(url, blockMode){
}
break;
case "allowEverything":
mode = "unblock";
mode = "allow";
break;
default:
console.log("Unknown blocking mode (" + blockMode + "). Default to block everything.");
@ -131,8 +99,6 @@ function errorToCallingStackMsg(error){
return msg;
}
exports.getDomainRegExpList = getDomainRegExpList;
exports.checkURL = checkURL;
exports.parseStackEntry = parseStackEntry;
exports.errorToCallingStackMsg = errorToCallingStackMsg;