From 6b359c9b8c49b2004c6b0313b40d23acc744455d Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 5 Feb 2016 18:48:01 -0800 Subject: [PATCH] Disrupt loading of ads from malicious/irresponsible providers. --- package.json | 7 +++++-- src/General/$.coffee | 6 +++++- src/General/Main.coffee | 12 ++++++++++++ src/meta/manifest.json | 1 + src/meta/metadata.js | 34 +++++++++++++++++++++++++--------- 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index f78bce9e4..c18ab2f42 100644 --- a/package.json +++ b/package.json @@ -20,13 +20,16 @@ "matches": [ "*://boards.4chan.org/*", "*://sys.4chan.org/*", + "*://www.4chan.org/*", "*://i.4cdn.org/*", - "*://www.4chan.org/banned", - "*://www.4chan.org/feedback", "https://www.google.com/recaptcha/api2/anchor?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*", "https://www.google.com/recaptcha/api2/frame?*&k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*", "*://www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*" ], + "exclude_matches": [ + "*://www.4chan.org/pass", + "*://www.4chan.org/pass?*" + ], "grants": [ "GM_getValue", "GM_setValue", diff --git a/src/General/$.coffee b/src/General/$.coffee index 7df9eda92..9ba79fc6a 100644 --- a/src/General/$.coffee +++ b/src/General/$.coffee @@ -314,7 +314,11 @@ $.globalEval = (code) -> $.rm script $.global = (fn) -> - $.globalEval "(#{fn})();" + if doc + $.globalEval "(#{fn})();" + else + # XXX dwb + fn() $.bytesToString = (size) -> unit = 0 # Bytes diff --git a/src/General/Main.coffee b/src/General/Main.coffee index e864dc468..ddaa9af8c 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -13,6 +13,18 @@ Main = $.ready -> Captcha.fixes.init() return + # Disrupt loading of ads from malicious/irresponsible providers. + $.global -> + nuke = (obj, prop) -> + try + Object.defineProperty obj, prop, + configurable: false + get: -> throw new Error() + set: -> throw new Error() + for prop in ['atOptions', 'adsterra_key', 'EpmadsConfig', 'epmads_key', 'EpomConfig', 'epom_key', 'exoDocumentProtocol'] + nuke window, prop + return + # Detect multiple copies of 4chan X $.on d, '4chanXInitFinished', -> if Main.expectInitFinished diff --git a/src/meta/manifest.json b/src/meta/manifest.json index edefb1ffb..0008f50f8 100644 --- a/src/meta/manifest.json +++ b/src/meta/manifest.json @@ -11,6 +11,7 @@ "content_scripts": [{ "js": ["script.js"], "matches": <%= JSON.stringify(meta.matches) %>, + "exclude_matches": <%= JSON.stringify(meta.exclude_matches) %>, "all_frames": true, "run_at": "document_start" }], diff --git a/src/meta/metadata.js b/src/meta/metadata.js index 23981cb7d..04f31e1a4 100644 --- a/src/meta/metadata.js +++ b/src/meta/metadata.js @@ -7,16 +7,32 @@ // @description <%= description %> // @license MIT; <%= meta.license %> <%= - meta.matches.map(function(match) { - if (/^\*/.test(match)) { - return ( - '// @include ' + match.replace(/^\*/, 'http') + '\n' + - '// @include ' + match.replace(/^\*/, 'https') - ); - } else { - return '// @include ' + match; + (function() { + function expand(items, regex, substitutions) { + var results = []; + items.forEach(function(item) { + if (regex.test(item)) { + substitutions.forEach(function(s) { + results.push(item.replace(regex, s)); + }); + } else { + results.push(item); + } + }); + return results; } - }).join('\n') + function expandMatches(matches) { + return expand(matches, /^\*/, ['http', 'https']); + } + return [].concat( + expandMatches(meta.matches).map(function(match) { + return '// @include ' + match; + }), + expandMatches(meta.exclude_matches).map(function(match) { + return '// @exclude ' + match; + }) + ).join('\n'); + })() %> <%= meta.grants.map(function(grant) {