| Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 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 | 
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 | 101 | 
| 102 function getMagic() | 102 function getMagic() | 
| 103 { | 103 { | 
| 104 return String.fromCharCode(Date.now() % 26 + 97) + | 104 return String.fromCharCode(Date.now() % 26 + 97) + | 
| 105 Math.floor(Math.random() * 982451653 + 982451653).toString(36); | 105 Math.floor(Math.random() * 982451653 + 982451653).toString(36); | 
| 106 } | 106 } | 
| 107 | 107 | 
| 108 function suppressMagicError(magic) | 108 function suppressMagicError(magic) | 
| 109 { | 109 { | 
| 110 let {onerror} = window; | 110 let {onerror} = window; | 
| 111 window.onerror = function(message, ...rest) | 111 window.onerror = function(message, ...rest) | 
| 
 
kzar
2018/07/16 16:33:15
The content script part of our snippet already run
 
 | |
| 112 { | 112 { | 
| 113 if (typeof message == "string" && message.includes(magic)) | 113 if (typeof message == "string" && message.includes(magic)) | 
| 114 return true; | 114 return true; | 
| 115 | 115 | 
| 116 if (typeof onerror instanceof Function) | 116 if (typeof onerror instanceof Function) | 
| 117 return onerror.call(this, message, ...rest); | 117 return onerror.call(this, message, ...rest); | 
| 118 }; | 118 }; | 
| 119 } | 119 } | 
| 120 | 120 | 
| 121 function log(...args) | 121 function log(...args) | 
| 122 { | 122 { | 
| 123 console.log(...args); | 123 console.log(...args); | 
| 124 } | 124 } | 
| 125 | 125 | 
| 126 exports.log = log; | 126 exports.log = log; | 
| 127 | 127 | 
| 128 // This is an implementation of the uabinject-defuser technique used by uBlock | |
| 129 // Origin | |
| 130 // https://github.com/uBlockOrigin/uAssets/blob/c091f861b63cd2254b8e9e4628f6bdcd 89d43caa/filters/resources.txt#L640 | |
| 128 function uabinjectDefuser() | 131 function uabinjectDefuser() | 
| 129 { | 132 { | 
| 130 window.trckd = true; | 133 window.trckd = true; | 
| 131 window.uabpdl = true; | 134 window.uabpdl = true; | 
| 132 window.uabInject = true; | 135 window.uabInject = true; | 
| 133 window.uabDetect = true; | 136 window.uabDetect = true; | 
| 134 } | 137 } | 
| 135 | 138 | 
| 136 exports["uabinject-defuser"] = makeInjector(uabinjectDefuser); | 139 exports["uabinject-defuser"] = makeInjector(uabinjectDefuser); | 
| 137 | 140 | 
| 138 // This is an implementation of the abort-current-inline-script technique used | 141 // This is an implementation of the abort-current-inline-script technique used | 
| 139 // by uBlock Origin | 142 // by uBlock Origin | 
| 140 // https://github.com/uBlockOrigin/uAssets/blob/68cf8a364fb55deb96264c4e546b58f4 c851d782/filters/resources.txt#L1943 | 143 // https://github.com/uBlockOrigin/uAssets/blob/68cf8a364fb55deb96264c4e546b58f4 c851d782/filters/resources.txt#L1943 | 
| 141 function abortCurrentInlineScript(target, needle) | 144 function abortCurrentInlineScript(target, needle) | 
| 
 
kzar
2018/07/16 16:33:15
Could you give me an example of `target` and `need
 
 | |
| 142 { | 145 { | 
| 143 if (!target) | 146 if (!target) | 
| 144 return; | 147 return; | 
| 145 | 148 | 
| 146 let re = null; | 149 let re = null; | 
| 147 | 150 | 
| 148 if (needle) | 151 if (needle) | 
| 149 { | 152 { | 
| 150 re = new RegExp(/^\/.+\/$/.test(needle) ? | 153 re = new RegExp(/^\/.+\/$/.test(needle) ? | 
| 151 needle.slice(1, -1) : | 154 needle.slice(1, -1) : | 
| 152 regexEscape(needle)); | 155 regexEscape(needle)); | 
| 153 } | 156 } | 
| 154 | 157 | 
| 155 let {owner, property} = findProperty(target) || {}; | 158 let {owner, property} = findProperty(target) || {}; | 
| 156 | 159 | 
| 157 if (!owner) | 160 if (!owner) | 
| 158 return; | 161 return; | 
| 159 | 162 | 
| 160 let descriptor = Object.getOwnPropertyDescriptor(owner, property); | 163 let descriptor = Object.getOwnPropertyDescriptor(owner, property); | 
| 161 if (descriptor && descriptor.get) | 164 if (descriptor && descriptor.get) | 
| 
 
kzar
2018/07/16 16:33:15
What's the idea with this check?
 
 | |
| 162 return; | 165 return; | 
| 163 | 166 | 
| 164 let magic = getMagic(); | 167 let magic = getMagic(); | 
| 165 | 168 | 
| 166 injectPropertyAccessValidator(owner, property, () => | 169 injectPropertyAccessValidator(owner, property, () => | 
| 167 { | 170 { | 
| 168 let element = document.currentScript; | 171 let element = document.currentScript; | 
| 169 if (element instanceof HTMLScriptElement && | 172 if (element instanceof HTMLScriptElement && | 
| 170 element.src == "" && (!re || re.test(element.textContent))) | 173 element.src == "" && (!re || re.test(element.textContent))) | 
| 171 { | 174 { | 
| 172 throw new ReferenceError(magic); | 175 throw new ReferenceError(magic); | 
| 
 
kzar
2018/07/16 16:33:15
How come you've used `ReferenceError` out of inter
 
 | |
| 173 } | 176 } | 
| 174 }); | 177 }); | 
| 175 | 178 | 
| 176 suppressMagicError(magic); | 179 suppressMagicError(magic); | 
| 177 } | 180 } | 
| 178 | 181 | 
| 179 exports["abort-current-inline-script"] = makeInjector(abortCurrentInlineScript); | 182 exports["abort-current-inline-script"] = makeInjector(abortCurrentInlineScript); | 
| LEFT | RIGHT |