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:
parent
97e0c6b9cd
commit
c10b382c93
7 changed files with 106 additions and 83 deletions
45
lib/lists.js
45
lib/lists.js
|
@ -6,7 +6,48 @@
|
|||
var preferences = require("sdk/simple-prefs");
|
||||
var prefService = require("sdk/preferences/service");
|
||||
var prefs = preferences.prefs;
|
||||
var sharedFunctions = require("./sharedFunctions");
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
var lists = {
|
||||
white: [],
|
||||
|
@ -15,7 +56,7 @@ var lists = {
|
|||
};
|
||||
|
||||
function updateList(type){
|
||||
lists[type] = sharedFunctions.getDomainRegExpList(prefs[type + "List"]);
|
||||
lists[type] = getDomainRegExpList(prefs[type + "List"]);
|
||||
}
|
||||
Object.keys(lists).forEach(function(type){
|
||||
preferences.on(type + "List", function(){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue