1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 20:46:39 +02: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

View file

@ -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");