Index: lib/content/snippets.js |
=================================================================== |
--- a/lib/content/snippets.js |
+++ b/lib/content/snippets.js |
@@ -62,8 +62,85 @@ |
exports.log = log; |
function uabinjectDefuser() |
{ |
window.trckd = window.uabpdl = window.uabInject = window.uabDetect = true; |
} |
exports["uabinject-defuser"] = makeInjector(uabinjectDefuser); |
+ |
+function abortCurrentInlineScript(target, needle) |
+{ |
+ "use strict"; |
+ |
+ if (!target) |
+ return; |
+ |
+ let reText = ".?"; |
+ |
+ if (needle) |
+ { |
+ reText = /^\/.+\/$/.test(needle) ? |
+ needle.slice(1, -1) : |
+ needle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); |
+ } |
+ |
+ let re = new RegExp(reText); |
+ let chain = target.split("."); |
+ |
+ let owner = window; |
+ let property = null; |
+ |
+ while (true) |
+ { |
+ property = chain.shift(); |
+ if (chain.length == 0) |
+ break; |
+ |
+ owner = owner[property]; |
+ if (!(owner instanceof Object)) |
+ return; |
+ } |
+ |
+ let descriptor = Object.getOwnPropertyDescriptor(owner, property); |
+ if (descriptor && descriptor.get) |
+ return; |
+ |
+ let magic = String.fromCharCode(Date.now() % 26 + 97) + |
+ Math.floor(Math.random() * 982451653 + 982451653).toString(36); |
+ let value = owner[property]; |
+ |
+ let validate = () => |
+ { |
+ let element = document.currentScript; |
+ if (element instanceof HTMLScriptElement && |
+ element.src == "" && re.test(element.textContent)) |
+ { |
+ throw new ReferenceError(magic); |
+ } |
+ }; |
+ |
+ Object.defineProperty(owner, property, { |
+ get() |
+ { |
+ validate(); |
+ return value; |
+ }, |
+ set(newValue) |
+ { |
+ validate(); |
+ value = newValue; |
+ } |
+ }); |
+ |
+ let {onerror} = window; |
+ window.onerror = function(message, ...rest) |
+ { |
+ if (typeof message == "string" && message.indexOf(magic) != -1) |
+ return true; |
+ |
+ if (onerror instanceof Function) |
+ return onerror.call(this, message, ...rest); |
+ }; |
+} |
+ |
+exports["abort-current-inline-script"] = makeInjector(abortCurrentInlineScript); |