1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-01-03 02:21:53 +01:00

Fixed PDF bug + added full RegExp support.

This commit is contained in:
kkapsner 2014-08-10 18:03:58 +02:00
parent 6d0fb5e1f1
commit 124d0a73a5
4 changed files with 24 additions and 7 deletions

Binary file not shown.

View File

@ -4,9 +4,9 @@ var askFunctionName = Math.random().toString(16);
function checkPDF(blocking){ function checkPDF(blocking){
if (unsafeWindow.document.contentType.match(/\/pdf$/i)){ if (unsafeWindow.document.contentType.match(/\/pdf$/i)){
self.port.emit("isPDF", blocking); self.port.emit("isPDF", blocking);
return false; return true;
} }
return true; return false;
} }
function block(force){ function block(force){

View File

@ -8,7 +8,24 @@ function getDomainRegExpList(domainList){
return !!entry.length; return !!entry.length;
}) })
.map(function(entry){ .map(function(entry){
return new RegExp("(?:^|\\.)" + entry.replace(/([\\\+\*\?\[\^\]\$\(\)\{\}\=\!\|\.])/g, "\\$1") + "\\.?$", "i"); 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);
}
}
};
}); });
} }
@ -52,14 +69,14 @@ function checkWorker(worker){
else { else {
var url = new URL(worker.url); var url = new URL(worker.url);
var inBlackList = blackList.some(function(entry){ var inBlackList = blackList.some(function(entry){
return url.hostname.match(entry); return entry.match(url);
}); });
if (inBlackList){ if (inBlackList){
worker.port.emit("block"); worker.port.emit("block");
} }
else { else {
var inWhiteList = whiteList.some(function(entry){ var inWhiteList = whiteList.some(function(entry){
return url.hostname.match(entry); return entry.match(url);
}); });
if (inWhiteList){ if (inWhiteList){
worker.port.emit("unblock"); worker.port.emit("unblock");

View File

@ -9,7 +9,7 @@
"title": "White list", "title": "White list",
"description": "Domains where the <canvas>-API should not be blocked. To add multiple domains seperate them by comma.", "description": "Domains where the <canvas>-API should not be blocked. To add multiple domains seperate them by comma.",
"type": "string", "type": "string",
"value": "kkapsner.de" "value": "kkapsner.de,^https?://(\\\\w+\\\\.)*google.[a-z]+/maps"
}, },
{ {
"name": "blockAll", "name": "blockAll",
@ -42,6 +42,6 @@
], ],
"author": "Korbinian Kapsner", "author": "Korbinian Kapsner",
"license": "MPL 2.0", "license": "MPL 2.0",
"version": "0.1", "version": "0.1.1",
"permissions": {"private-browsing": true} "permissions": {"private-browsing": true}
} }