diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/canvasblocker.xpi b/canvasblocker.xpi new file mode 100644 index 0000000..939f538 Binary files /dev/null and b/canvasblocker.xpi differ diff --git a/data/inject.js b/data/inject.js new file mode 100644 index 0000000..f3fc83d --- /dev/null +++ b/data/inject.js @@ -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); \ No newline at end of file diff --git a/doc/main.md b/doc/main.md new file mode 100644 index 0000000..e69de29 diff --git a/lib/main.js b/lib/main.js new file mode 100644 index 0000000..3f3c615 --- /dev/null +++ b/lib/main.js @@ -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); + }); + }, +}); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..4899fba --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "canvasblocker", + "title": "CanvasBlocker", + "id": "CanvasBlocker@kkapsner.de", + "description": "Blocks the JS-API for modifying ", + "preferences": [ + { + "name": "whiteList", + "title": "White list", + "description": "Domains where the -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} +} diff --git a/test/test-main.js b/test/test-main.js new file mode 100644 index 0000000..147f98a --- /dev/null +++ b/test/test-main.js @@ -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);