Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/content/snippets.js

Issue 29828604: Issue 6790 - Implement uabinject-defuser snippet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add attribution Created July 13, 2018, 12:59 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /* eslint-env webextensions */
18 /* eslint no-console: "off" */ 19 /* eslint no-console: "off" */
19 20
20 "use strict"; 21 "use strict";
21 22
23 function injectCode(code)
24 {
25 let script = document.createElement("script");
26
27 script.type = "application/javascript";
28 script.async = false;
29
30 // Firefox 58 only bypasses site CSPs when assigning to 'src',
31 // while Chrome 67 only bypasses site CSPs when using 'textContent'.
32 if (browser.runtime.getURL("").startsWith("chrome-extension://"))
33 {
34 script.textContent = code;
35 document.documentElement.appendChild(script);
36 }
37 else
38 {
39 let url = URL.createObjectURL(new Blob([code]));
40 script.src = url;
41 document.documentElement.appendChild(script);
42 URL.revokeObjectURL(url);
43 }
44
45 document.documentElement.removeChild(script);
46 }
47
48 function stringifyFunctionCall(func, ...params)
49 {
50 return `"use strict";(${func})(${params.map(JSON.stringify).join(",")});`;
51 }
52
53 function makeInjector(injectable)
54 {
55 return (...args) => injectCode(stringifyFunctionCall(injectable, ...args));
56 }
57
22 function log(...args) 58 function log(...args)
23 { 59 {
24 console.log(...args); 60 console.log(...args);
25 } 61 }
26 62
27 exports.log = log; 63 exports.log = log;
64
65 // This is an implementation of the uabinject-defuser technique used by uBlock
66 // Origin
67 // https://github.com/uBlockOrigin/uAssets/blob/c091f861b63cd2254b8e9e4628f6bdcd 89d43caa/filters/resources.txt#L640
68 function uabinjectDefuser()
69 {
70 window.trckd = true;
71 window.uabpdl = true;
72 window.uabInject = true;
73 window.uabDetect = true;
74 }
75
76 exports["uabinject-defuser"] = makeInjector(uabinjectDefuser);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld