1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-01-03 10:31:54 +01:00

Initial Commit

This commit is contained in:
kkapsner 2014-07-31 03:05:51 +02:00
parent c8410b6536
commit 0ab4f1b7d3
7 changed files with 104 additions and 0 deletions

0
README.md Normal file
View File

BIN
canvasblocker.xpi Normal file

Binary file not shown.

12
data/inject.js Normal file
View File

@ -0,0 +1,12 @@
var getContext = unsafeWindow.HTMLCanvasElement.prototype.getContext
function block(){
unsafeWindow.HTMLCanvasElement.prototype.getContext = null;
}
function unblock(){
unsafeWindow.HTMLCanvasElement.prototype.getContext = getContext;
}
self.port.on("block", block);
self.port.on("unblock", unblock);
self.port.on("detach", unblock);

0
doc/main.md Normal file
View File

54
lib/main.js Normal file
View File

@ -0,0 +1,54 @@
var self = require("sdk/self");
var pageMod = require("sdk/page-mod");
var preferences = require("sdk/simple-prefs");
var prefs = preferences.prefs;
var {URL} = require("sdk/url");
var workers = [];
var whiteList;
updateWhiteList();
function updateWhiteList(){
whiteList = prefs.whiteList.split(",").map(function(entry){
return new RegExp("(?:^|\\.)" + entry.replace(/([\\\+\*\?\[\^\]\$\(\)\{\}\=\!\|\.])/g, "\\$1") + "\\.?$", "i");
});
}
function detachWorker(worker, workerArray) {
var index = workerArray.indexOf(worker);
if (index != -1){
workerArray.splice(index, 1);
}
}
function checkWorker(worker){
var url = new URL(worker.url);
if (prefs.blockAll || !whiteList.some(function(entry){
return url.hostname.match(entry);
})){
worker.port.emit("block");
}
else {
worker.port.emit("unblock");
}
}
preferences.on("whiteList", function(){
updateWhiteList();
workers.forEach(checkWorker);
});
preferences.on("blockAll", function(){
workers.forEach(checkWorker);
});
pageMod.PageMod({
include: "*",
contentScriptWhen: "start",
contentScriptFile: self.data.url("inject.js"),
onAttach: function(worker){
checkWorker(worker);
workers.push(worker);
worker.on("detach", function(){
detachWorker(this, workers);
});
},
});

26
package.json Normal file
View File

@ -0,0 +1,26 @@
{
"name": "canvasblocker",
"title": "CanvasBlocker",
"id": "CanvasBlocker@kkapsner.de",
"description": "Blocks the JS-API for modifying <canvas>",
"preferences": [
{
"name": "whiteList",
"title": "White list",
"description": "Domains where the <canvas>-API should not be blocked. To add multiple domains seperate them by comma.",
"type": "string",
"value": "kkapsner.de"
},
{
"name": "blockAll",
"title": "Block everything",
"description": "If you want to block everything (ignore the white list).",
"type": "bool",
"value": false
}
],
"author": "Korbinian Kapsner",
"license": "MPL 2.0",
"version": "0.1",
"permissions": {"private-browsing": true}
}

12
test/test-main.js Normal file
View File

@ -0,0 +1,12 @@
var main = require("./main");
exports["test main"] = function(assert) {
assert.pass("Unit test running!");
};
exports["test main async"] = function(assert, done) {
assert.pass("async Unit test running!");
done();
};
require("sdk/test").run(exports);