Disrupt loading of ads from malicious/irresponsible providers.

This commit is contained in:
ccd0 2016-02-05 18:48:01 -08:00
parent 94502f64cb
commit 6b359c9b8c
5 changed files with 48 additions and 12 deletions

View File

@ -20,13 +20,16 @@
"matches": [ "matches": [
"*://boards.4chan.org/*", "*://boards.4chan.org/*",
"*://sys.4chan.org/*", "*://sys.4chan.org/*",
"*://www.4chan.org/*",
"*://i.4cdn.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/anchor?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*",
"https://www.google.com/recaptcha/api2/frame?*&k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*", "https://www.google.com/recaptcha/api2/frame?*&k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*",
"*://www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*" "*://www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc*"
], ],
"exclude_matches": [
"*://www.4chan.org/pass",
"*://www.4chan.org/pass?*"
],
"grants": [ "grants": [
"GM_getValue", "GM_getValue",
"GM_setValue", "GM_setValue",

View File

@ -314,7 +314,11 @@ $.globalEval = (code) ->
$.rm script $.rm script
$.global = (fn) -> $.global = (fn) ->
$.globalEval "(#{fn})();" if doc
$.globalEval "(#{fn})();"
else
# XXX dwb
fn()
$.bytesToString = (size) -> $.bytesToString = (size) ->
unit = 0 # Bytes unit = 0 # Bytes

View File

@ -13,6 +13,18 @@ Main =
$.ready -> Captcha.fixes.init() $.ready -> Captcha.fixes.init()
return 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 # Detect multiple copies of 4chan X
$.on d, '4chanXInitFinished', -> $.on d, '4chanXInitFinished', ->
if Main.expectInitFinished if Main.expectInitFinished

View File

@ -11,6 +11,7 @@
"content_scripts": [{ "content_scripts": [{
"js": ["script.js"], "js": ["script.js"],
"matches": <%= JSON.stringify(meta.matches) %>, "matches": <%= JSON.stringify(meta.matches) %>,
"exclude_matches": <%= JSON.stringify(meta.exclude_matches) %>,
"all_frames": true, "all_frames": true,
"run_at": "document_start" "run_at": "document_start"
}], }],

View File

@ -7,16 +7,32 @@
// @description <%= description %> // @description <%= description %>
// @license MIT; <%= meta.license %> // @license MIT; <%= meta.license %>
<%= <%=
meta.matches.map(function(match) { (function() {
if (/^\*/.test(match)) { function expand(items, regex, substitutions) {
return ( var results = [];
'// @include ' + match.replace(/^\*/, 'http') + '\n' + items.forEach(function(item) {
'// @include ' + match.replace(/^\*/, 'https') if (regex.test(item)) {
); substitutions.forEach(function(s) {
} else { results.push(item.replace(regex, s));
return '// @include ' + match; });
} 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) { meta.grants.map(function(grant) {