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: Created July 12, 2018, 4:31 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 no-console: "off" */ 18 /* eslint no-console: "off" */
19 19
20 "use strict"; 20 "use strict";
21 21
22 function injectCode(code)
23 {
24 let script = document.createElement("script");
25
26 script.type = "application/javascript";
27 script.async = false;
28
29 // Firefox 58 only bypasses site CSPs when assigning to 'src',
30 // while Chrome 67 only bypasses site CSPs when using 'textContent'.
31 if (browser.runtime.getURL("").startsWith("chrome-extension://"))
32 {
33 script.textContent = code;
34 document.documentElement.appendChild(script);
35 }
36 else
37 {
38 let url = URL.createObjectURL(new Blob([code]));
39 script.src = url;
40 document.documentElement.appendChild(script);
41 URL.revokeObjectURL(url);
42 }
43
44 document.documentElement.removeChild(script);
45 }
46
47 function stringifyFunctionCall(func, ...params)
48 {
49 return `(${func})(${params.map(JSON.stringify).join(",")});`;
50 }
51
52 function makeInjector(injectable)
53 {
54 return (...args) => injectCode(stringifyFunctionCall(injectable, ...args));
55 }
56
22 function log(...args) 57 function log(...args)
23 { 58 {
24 console.log(...args); 59 console.log(...args);
25 } 60 }
26 61
27 exports.log = log; 62 exports.log = log;
63
64 function uabinjectDefuser()
65 {
66 window.trckd = window.uabpdl = window.uabInject = window.uabDetect = true;
67 }
68
69 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