2015-09-06 12:26:50 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
|
|
|
|
var preferences = require("sdk/simple-prefs");
|
|
|
|
var prefService = require("sdk/preferences/service");
|
|
|
|
var prefs = preferences.prefs;
|
2015-09-06 15:40:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2015-09-06 12:26:50 +02:00
|
|
|
|
|
|
|
var lists = {
|
|
|
|
white: [],
|
2015-10-24 10:44:51 +02:00
|
|
|
"ignore": [],
|
2015-09-06 12:26:50 +02:00
|
|
|
black: []
|
|
|
|
};
|
|
|
|
|
|
|
|
function updateList(type){
|
2015-09-08 11:42:32 +02:00
|
|
|
"use strict";
|
|
|
|
|
2015-09-06 15:40:34 +02:00
|
|
|
lists[type] = getDomainRegExpList(prefs[type + "List"]);
|
2015-09-06 12:26:50 +02:00
|
|
|
}
|
|
|
|
Object.keys(lists).forEach(function(type){
|
2015-09-08 11:42:32 +02:00
|
|
|
"use strict";
|
|
|
|
|
2015-09-06 12:26:50 +02:00
|
|
|
preferences.on(type + "List", function(){
|
|
|
|
updateList(type);
|
|
|
|
});
|
|
|
|
updateList(type);
|
|
|
|
});
|
|
|
|
|
|
|
|
exports.get = function getList(type){
|
2015-09-08 11:42:32 +02:00
|
|
|
"use strict";
|
|
|
|
|
2015-09-06 12:26:50 +02:00
|
|
|
return lists[type];
|
2015-09-08 11:42:32 +02:00
|
|
|
};
|
2015-09-06 12:26:50 +02:00
|
|
|
exports.appendTo = function appendToList(type, entry){
|
2015-09-08 11:42:32 +02:00
|
|
|
"use strict";
|
|
|
|
|
2015-09-06 12:26:50 +02:00
|
|
|
prefs[type + "List"] += (prefs[type + "List"]? ",": "") + entry;
|
2015-10-24 10:44:51 +02:00
|
|
|
prefService.set("extensions.CanvasBlocker@kkapsner.de." + type + "List", prefs[type + "List"]);
|
2015-09-06 12:26:50 +02:00
|
|
|
updateList(type);
|
2015-09-08 11:42:32 +02:00
|
|
|
};
|
2015-09-06 12:26:50 +02:00
|
|
|
exports.update = updateList;
|