From 0ab4f1b7d32a9e8e4af41530e607c2aad10cd1bd Mon Sep 17 00:00:00 2001 From: kkapsner Date: Thu, 31 Jul 2014 03:05:51 +0200 Subject: [PATCH] Initial Commit --- README.md | 0 canvasblocker.xpi | Bin 0 -> 9028 bytes data/inject.js | 12 +++++++++++ doc/main.md | 0 lib/main.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 26 ++++++++++++++++++++++ test/test-main.js | 12 +++++++++++ 7 files changed, 104 insertions(+) create mode 100644 README.md create mode 100644 canvasblocker.xpi create mode 100644 data/inject.js create mode 100644 doc/main.md create mode 100644 lib/main.js create mode 100644 package.json create mode 100644 test/test-main.js 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 0000000000000000000000000000000000000000..939f5382476e77091a5db12bffbbfe2bf023e3f3 GIT binary patch literal 9028 zcma)C1yo#1w#8|raR_d~-QC@t;O_1&!5xBYkl?|BdywGn?gV!Y5CVLd_j&eb-u%<+ zcHMQm_Nh~KOU~N66{Nu-&_F;y03b=2Pa;P=mCb@+ARzA{KtSN0pIX>DIU878(>WTO z+9)f^FEJqbif{5S2Xs$;%(q~bpfrFF=>~xTvRHhGakBVI=4z~G-eU3OV~diG_9OAO z<+O$SeOrc3*$|lSxccXrCiV+qL(sUitBdP4gVeHusn1IK4f z$-P=b(HnAD1j%Tz(q@CO%1CH&1sCa*>EKd!iYf%{A-PEDR>XNM|49fa|E9B_jakwk}$Icso4y+;yxFEmHchIkh$ zWza$rK!(cC`laj3M=K^^-%>l$fy=wdj%w!>W?E7uk?NwAZAtBze^%whOIA)JRnz`z ze_t?e7`}7qI6z%Gev364kUU<~QY0hvei}k=j5m-ColFtc+V@_fgq8D)M^fzPrDfjf zDN9v{Dj7%J`Q&NPP-r|eZd&$9{farQJm`X^w6{9%k}@FWe6;SNjyqN!o^m*VeFnbY zM9>`B?pOviK8Ey*8S(8f_L6^}8d&pT*4-{p;pajmW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9U|}F$i+A4XjFLO-47#URgeGhLI{Tr+viW zUEf2frDeM*d+N`2yoZpIS^iaYdkf|AVr)nesku8ph8%e^J>*hjk!9l@n)}UVzLWG| z4WKkjOlgQsIxuA!Nf=6)N=i*i3OU5fO|g(&_BhL6Oj%_5=lSf#a&eeY%HZi8jmGe9 z1d(YlWi#^>(dg!%2aNzS^Ap_LB>Gv>#`-_Xilu%tt~Zy2>!AW&a{%?xz}?F5SEHRR zZ3Ir96>Va}#?IEl=JYpwat?)#StB?pYs0F65){^munElR1cVA(H&GqZ9is-}4q z@XJa-*EJ10Cz-m5x-X3sqO~zQrEox>u?wR?*0y|RpBA&kV?T{&D89-+KCJUCK-Cjn zVPiNHB;&Xe-2%82Jvpp))*^WW%FPHq)dmquO=r-KFz2>T4mWvrGOJALOuF4hKryJz z&U9V7MyP2M6$uz>(UA&J7RN}ub#;pF?NZDrw?Q_V6)BdF{6fj=sFmB4XMWIb7 zkgW+0aq?IN7A##`HGt?d4YA)r=>pP&LO&}idQ#85|likbQTpo%o)X#u3=|CQU(4y=Yv0f7>|a*z|5E%(3I99r z?^5P(Fc6S>f6M3N=5>ue3!8rj{#}{-133M>*#A+d`@_`>=>O_!uda>-4W6a^-&MBP z9{&dVyUz9s$_EYk9rT;(_D6I7UT1qn*86unBmbgpL+9> z+r8ScVAMZ&`QJ?MHK2c=>%F?F_wV~}u71z_{wchdBe;uxWpLD%? zs`p?1FP{E41^cJaUXIaMI~LT!`Ol%f9;$x~-OImS{(h{!`l|O&dG_`14p{|hNT`=u PNY5XZ=b8TVUm^St<+*G* literal 0 HcmV?d00001 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);