mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
Version 0.2.0
Reenabled notifications Code cleanup.
This commit is contained in:
parent
97e0c6b9cd
commit
c10b382c93
Binary file not shown.
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(){
|
||||
|
32
lib/main.js
32
lib/main.js
@ -5,13 +5,11 @@
|
||||
(function(){
|
||||
"use strict";
|
||||
require("./stylePreferencePane");
|
||||
// require("./disableWithoutDocumentElement");
|
||||
const {changedFunctions} = require("./modifiedAPI");
|
||||
const {notify} = require("./notifications");
|
||||
const lists = require("./lists");
|
||||
|
||||
const sharedFunctions = require("./sharedFunctions");
|
||||
// preferences
|
||||
|
||||
const observers = require("sdk/system/events");
|
||||
const { when: unload } = require("sdk/system/unload");
|
||||
@ -20,7 +18,23 @@
|
||||
const prefs = preferences.prefs;
|
||||
|
||||
function checkURL(url){
|
||||
return sharedFunctions.checkURL(url, prefs.blockMode);
|
||||
var match = sharedFunctions.checkURL(url, prefs.blockMode).match(/^(block|allow|fake)(|Readout|Everything|Context)$/);
|
||||
if (match){
|
||||
return {
|
||||
type: (match[2] === "Everything" || match[2] === "")?
|
||||
["context", "readout"]:
|
||||
[match[2].toLowerCase()],
|
||||
mode: match[1]
|
||||
};
|
||||
|
||||
}
|
||||
else {
|
||||
return {
|
||||
type: ["context", "readout"],
|
||||
mode: "block"
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var apiNames = Object.keys(changedFunctions);
|
||||
@ -39,12 +53,14 @@
|
||||
configureable: false,
|
||||
get: function(){
|
||||
var status = checkURL(window.location);
|
||||
if (status === changedFunction.mode){
|
||||
if (status.type.indexOf(changedFunction.type) !== -1){
|
||||
var callingStackMsg = sharedFunctions.errorToCallingStackMsg(new Error());
|
||||
switch (status){
|
||||
case "fakeReadout":
|
||||
// notify(window, callingStackMsg);
|
||||
return changedFunction.fake;
|
||||
switch (status.mode){
|
||||
case "allow":
|
||||
return original;
|
||||
case "fake":
|
||||
notify(window, callingStackMsg);
|
||||
return changedFunction.fake || undef;
|
||||
//case "block":
|
||||
default:
|
||||
return undef;
|
||||
|
@ -5,50 +5,48 @@
|
||||
"use strict";
|
||||
|
||||
function getFakeCanvas(window, original){
|
||||
var canvas = original.cloneNode(true);
|
||||
var context = window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d");
|
||||
var imageData = window.CanvasRenderingContext2D.prototype.getImageData.call(context, 0, 0, canvas.width, canvas.height);
|
||||
var context = window.HTMLCanvasElement.prototype.getContext.call(original, "2d");
|
||||
var imageData = window.CanvasRenderingContext2D.prototype.getImageData.call(context, 0, 0, original.width, original.height);
|
||||
var data = imageData.data;
|
||||
|
||||
for (var i = 0, l = data.length; i < l; i += 1){
|
||||
var value = 0xFF - data[i];
|
||||
if (value > 0x80){
|
||||
value = value ^ Math.floor(Math.random() * 0x40);
|
||||
}
|
||||
else if (value > 0x40){
|
||||
var value = data[i];
|
||||
if (value >= 0x80){
|
||||
value = value ^ Math.floor(Math.random() * 0x20);
|
||||
}
|
||||
else if (value > 0x20){
|
||||
else if (value >= 0x40){
|
||||
value = value ^ Math.floor(Math.random() * 0x10);
|
||||
}
|
||||
else if (value > 0x10){
|
||||
else if (value >= 0x20){
|
||||
value = value ^ Math.floor(Math.random() * 0x08);
|
||||
}
|
||||
else if (value > 0x08){
|
||||
else if (value >= 0x10){
|
||||
value = value ^ Math.floor(Math.random() * 0x04);
|
||||
}
|
||||
else if (value > 0x04){
|
||||
else if (value >= 0x08){
|
||||
value = value ^ Math.floor(Math.random() * 0x02);
|
||||
}
|
||||
else if (value > 0x02){
|
||||
else if (value >= 0x04){
|
||||
value = value ^ Math.floor(Math.random() * 0x01);
|
||||
}
|
||||
data[i] = 0xFF - value;
|
||||
data[i] = value;
|
||||
}
|
||||
var canvas = original.cloneNode(true);
|
||||
var context = window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d");
|
||||
context.putImageData(imageData, 0, 0);
|
||||
return canvas;
|
||||
}
|
||||
function getWindow(canvas){
|
||||
console.log(canvas);
|
||||
return canvas.ownerDocument.defaultView;
|
||||
}
|
||||
// changed functions and their fakes
|
||||
exports.changedFunctions = {
|
||||
getContext: {
|
||||
mode: "block",
|
||||
type: "context",
|
||||
object: "HTMLCanvasElement"
|
||||
},
|
||||
toDataURL: {
|
||||
mode: "fakeReadout",
|
||||
type: "readout",
|
||||
object: "HTMLCanvasElement",
|
||||
fake: function toDataURL(){
|
||||
var window = getWindow(this);
|
||||
@ -56,7 +54,7 @@
|
||||
}
|
||||
},
|
||||
toBlob: {
|
||||
mode: "fakeReadout",
|
||||
type: "readout",
|
||||
object: "HTMLCanvasElement",
|
||||
fake: function toBlob(callback){
|
||||
var window = getWindow(this);
|
||||
@ -65,7 +63,7 @@
|
||||
exportOptions: {allowCallbacks: true}
|
||||
},
|
||||
mozGetAsFile: {
|
||||
mode: "fakeReadout",
|
||||
type: "readout",
|
||||
object: "HTMLCanvasElement",
|
||||
mozGetAsFile: function mozGetAsFile(callbak){
|
||||
var window = getWindow(this);
|
||||
@ -73,7 +71,7 @@
|
||||
}
|
||||
},
|
||||
getImageData: {
|
||||
mode: "fakeReadout",
|
||||
type: "readout",
|
||||
object: "CanvasRenderingContext2D",
|
||||
fake: function getImageData(sx, sy, sw, sh){
|
||||
var window = getWindow(this.canvas);
|
||||
@ -88,7 +86,7 @@
|
||||
}
|
||||
},
|
||||
readPixels: {
|
||||
mode: "fakeReadout",
|
||||
type: "readout",
|
||||
object: "WebGLRenderingContext",
|
||||
fake: function readPixels(x, y, width, height, format, type, pixels){
|
||||
var window = getWindow(this.canvas);
|
||||
|
@ -18,11 +18,9 @@ exports.notify = function(window, callingStackMsg){
|
||||
var domain = contentURL.hostname;
|
||||
var message = _("fakedReadout").replace(/\{url\}/g, domain);
|
||||
|
||||
// var tab = tabUtils.getTabForId(worker.tab.id);
|
||||
// var tabBrowser = tabUtils.getTabBrowserForTab(tab);
|
||||
// var browser = tabUtils.getBrowserForTab(tab);
|
||||
var tabBrowser = tabUtils.getTabBrowser(window);
|
||||
var browser = windowUtils.getOwnerBrowserWindow(window);
|
||||
var tab = tabUtils.getTabForContentWindow(window);
|
||||
var tabBrowser = tabUtils.getTabBrowserForTab(tab);
|
||||
var browser = tabUtils.getBrowserForTab(tab);
|
||||
|
||||
var notifyBox = tabBrowser.getNotificationBox(browser);
|
||||
var notification = notifyBox.getNotificationWithValue("fake-readout");
|
||||
|
@ -20,51 +20,11 @@ var _ = function(name, replace){
|
||||
return str;
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
function checkURL(url, blockMode){
|
||||
"use strict";
|
||||
if (url.protocol === "about:") {
|
||||
return "unblock";
|
||||
if (url.protocol === "about:" || url.protocol == "chrome:") {
|
||||
return "allow";
|
||||
}
|
||||
|
||||
var mode = "block";
|
||||
@ -72,9 +32,17 @@ function checkURL(url, blockMode){
|
||||
case "blockEverything":
|
||||
mode = "block";
|
||||
break;
|
||||
case "block":
|
||||
case "blockContext":
|
||||
case "blockReadout":
|
||||
case "fake":
|
||||
case "fakeContext":
|
||||
case "fakeReadout":
|
||||
case "allow":
|
||||
case "allowContext":
|
||||
case "allowReadout":
|
||||
if (url && lists.get("white").match(url)){
|
||||
mode = "unblock";
|
||||
mode = "allow";
|
||||
}
|
||||
else if (url && lists.get("black").match(url)){
|
||||
mode = "block";
|
||||
@ -84,7 +52,7 @@ function checkURL(url, blockMode){
|
||||
}
|
||||
break;
|
||||
case "allowEverything":
|
||||
mode = "unblock";
|
||||
mode = "allow";
|
||||
break;
|
||||
default:
|
||||
console.log("Unknown blocking mode (" + blockMode + "). Default to block everything.");
|
||||
@ -131,8 +99,6 @@ function errorToCallingStackMsg(error){
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
exports.getDomainRegExpList = getDomainRegExpList;
|
||||
exports.checkURL = checkURL;
|
||||
exports.parseStackEntry = parseStackEntry;
|
||||
exports.errorToCallingStackMsg = errorToCallingStackMsg;
|
@ -22,6 +22,10 @@
|
||||
"type": "menulist",
|
||||
"value": "fakeReadout",
|
||||
"options": [
|
||||
{
|
||||
"value": "blockEverything",
|
||||
"label": "block everything"
|
||||
},
|
||||
{
|
||||
"value": "blockReadout",
|
||||
"label": "block readout API"
|
||||
@ -52,6 +56,6 @@
|
||||
"main": "lib/main.js",
|
||||
"author": "Korbinian Kapsner",
|
||||
"license": "MPL 2.0",
|
||||
"version": "0.1.9-Development",
|
||||
"version": "0.2.0-Development",
|
||||
"permissions": {"private-browsing": true}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user