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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/content/snippets.js
===================================================================
--- a/lib/content/snippets.js
+++ b/lib/content/snippets.js
@@ -14,14 +14,56 @@
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
/* eslint no-console: "off" */
"use strict";
+function injectCode(code)
+{
+ let script = document.createElement("script");
+
+ script.type = "application/javascript";
+ script.async = false;
+
+ // Firefox 58 only bypasses site CSPs when assigning to 'src',
+ // while Chrome 67 only bypasses site CSPs when using 'textContent'.
+ if (browser.runtime.getURL("").startsWith("chrome-extension://"))
+ {
+ script.textContent = code;
+ document.documentElement.appendChild(script);
+ }
+ else
+ {
+ let url = URL.createObjectURL(new Blob([code]));
+ script.src = url;
+ document.documentElement.appendChild(script);
+ URL.revokeObjectURL(url);
+ }
+
+ document.documentElement.removeChild(script);
+}
+
+function stringifyFunctionCall(func, ...params)
+{
+ return `(${func})(${params.map(JSON.stringify).join(",")});`;
+}
+
+function makeInjector(injectable)
+{
+ return (...args) => injectCode(stringifyFunctionCall(injectable, ...args));
+}
+
function log(...args)
{
console.log(...args);
}
exports.log = log;
+
+function uabinjectDefuser()
+{
+ window.trckd = window.uabpdl = window.uabInject = window.uabDetect = true;
+}
+
+exports["uabinject-defuser"] = makeInjector(uabinjectDefuser);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld