mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 10:31:54 +01:00
Fixed PDF bug + added full RegExp support.
This commit is contained in:
parent
6d0fb5e1f1
commit
124d0a73a5
Binary file not shown.
@ -4,9 +4,9 @@ var askFunctionName = Math.random().toString(16);
|
||||
function checkPDF(blocking){
|
||||
if (unsafeWindow.document.contentType.match(/\/pdf$/i)){
|
||||
self.port.emit("isPDF", blocking);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function block(force){
|
||||
|
23
lib/main.js
23
lib/main.js
@ -8,7 +8,24 @@ function getDomainRegExpList(domainList){
|
||||
return !!entry.length;
|
||||
})
|
||||
.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 {
|
||||
var url = new URL(worker.url);
|
||||
var inBlackList = blackList.some(function(entry){
|
||||
return url.hostname.match(entry);
|
||||
return entry.match(url);
|
||||
});
|
||||
if (inBlackList){
|
||||
worker.port.emit("block");
|
||||
}
|
||||
else {
|
||||
var inWhiteList = whiteList.some(function(entry){
|
||||
return url.hostname.match(entry);
|
||||
return entry.match(url);
|
||||
});
|
||||
if (inWhiteList){
|
||||
worker.port.emit("unblock");
|
||||
|
@ -9,7 +9,7 @@
|
||||
"title": "White list",
|
||||
"description": "Domains where the <canvas>-API should not be blocked. To add multiple domains seperate them by comma.",
|
||||
"type": "string",
|
||||
"value": "kkapsner.de"
|
||||
"value": "kkapsner.de,^https?://(\\\\w+\\\\.)*google.[a-z]+/maps"
|
||||
},
|
||||
{
|
||||
"name": "blockAll",
|
||||
@ -42,6 +42,6 @@
|
||||
],
|
||||
"author": "Korbinian Kapsner",
|
||||
"license": "MPL 2.0",
|
||||
"version": "0.1",
|
||||
"version": "0.1.1",
|
||||
"permissions": {"private-browsing": true}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user