1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 12:36:37 +02:00

Removed pageMod and many not needed features.

Notifications not working.
This commit is contained in:
kkapsner 2015-09-06 12:26:50 +02:00
parent 195d780bf8
commit 97e0c6b9cd
8 changed files with 348 additions and 661 deletions

View file

@ -3,6 +3,23 @@
* 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/. */
const lists = require("./lists");
const preferences = require("sdk/simple-prefs");
const prefs = preferences.prefs;
// Translation
var translate = require("sdk/l10n").get;
var _ = function(name, replace){
var str = translate(name) || name;
if (replace){
// replace generic content in the transation by given parameter
Object.keys(replace).forEach(function(name){
str = str.replace(new RegExp("{" + name + "}", "g"), replace[name]);
});
}
return str;
};
function getDomainRegExpList(domainList){
"use strict";
@ -44,44 +61,28 @@ function getDomainRegExpList(domainList){
return list;
}
function checkURL(url, blockMode, whiteList, blackList){
function checkURL(url, blockMode){
"use strict";
if (url.protocol === "about:") {
return "unblock";
}
var mode = "block";
switch (blockMode){
case "blockEverything":
mode = "block";
break;
case "allowOnlyWhiteList":
if (url && whiteList.match(url)){
mode = "unblock";
}
else {
mode = "block";
}
break;
case "ask":
case "blockReadout":
case "fakeReadout":
case "askReadout":
if (url && whiteList.match(url)){
if (url && lists.get("white").match(url)){
mode = "unblock";
}
else if (url && blackList.match(url)){
else if (url && lists.get("black").match(url)){
mode = "block";
}
else {
mode = blockMode;
}
break;
case "blockOnlyBlackList":
if (url && blackList.match(url)){
mode = "block";
}
else {
mode = "unblock";
}
break;
case "allowEverything":
mode = "unblock";
break;
@ -91,8 +92,47 @@ function checkURL(url, blockMode, whiteList, blackList){
return mode;
}
try {
exports.getDomainRegExpList = getDomainRegExpList;
exports.checkURL = checkURL;
// Stack parsing
function parseStackEntry(entry){
var m = /@(.*):(\d*):(\d*)$/.exec(entry) || ["", entry, "--", "--"];
return {
url: m[1],
line: m[2],
column: m[3],
raw: entry
};
}
catch(e){}
// parse calling stack
function errorToCallingStackMsg(error){
var msg = "";
var callers = error.stack.trim().split("\n");
//console.log(callers);
var findme = callers.shift(); // Remove us from the stack
findme = findme.replace(/(:[0-9]+){1,2}$/, ""); // rm line & column
// Eliminate squashed stack. stack may contain 2+ stacks, but why...
var inDoubleStack = false;
callers = callers.filter(function(caller){
var doubleStackStart = caller.search(findme) !== -1;
inDoubleStack = inDoubleStack || doubleStackStart;
return !inDoubleStack;
});
msg += "\n\n" + _("sourceOutput") + ": ";
if (prefs.showCompleteCallingStack){
msg += callers.reduce(function(stack, c){
return stack + "\n\t" + _("stackEntryOutput", parseStackEntry(c));
}, "");
}
else{
msg += _("stackEntryOutput", parseStackEntry(callers[0]));
}
return msg;
}
exports.getDomainRegExpList = getDomainRegExpList;
exports.checkURL = checkURL;
exports.parseStackEntry = parseStackEntry;
exports.errorToCallingStackMsg = errorToCallingStackMsg;