mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Add abort-current-script scriptlet
This scriplet supersedes abort-current-inline-script (acis), and accepts an optional third argument which is matched against the `src` property of script resources. When the third argument is not provided, the scriptlet behaves essentially the same as `acis`, and because of this `acis` is now aliased to `abort-current-script`, and all existing `acis` filters will execute with no change in behavior. In the long run, usage of `abort-current-inline-script` or its alias `acis` should go away and be replaced with `abort-current-script` or its alias `acs`.
This commit is contained in:
parent
11e6ff5782
commit
ebc42ae21e
@ -32,18 +32,30 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// abort-current-inline-script.js
|
/// abort-current-script.js
|
||||||
|
/// alias acs.js
|
||||||
|
/// alias abort-current-inline-script.js
|
||||||
/// alias acis.js
|
/// alias acis.js
|
||||||
(function() {
|
(function() {
|
||||||
const target = '{{1}}';
|
const target = '{{1}}';
|
||||||
if ( target === '' || target === '{{1}}' ) { return; }
|
if ( target === '' || target === '{{1}}' ) { return; }
|
||||||
|
const reRegexEscape = /[.*+?^${}()|[\]\\]/g;
|
||||||
const needle = '{{2}}';
|
const needle = '{{2}}';
|
||||||
let reText = '.?';
|
const reText = (( ) => {
|
||||||
if ( needle !== '' && needle !== '{{2}}' ) {
|
if ( needle === '' || needle === '{{2}}' ) { return /^/; }
|
||||||
reText = /^\/.+\/$/.test(needle)
|
if ( /^\/.+\/$/.test(needle) ) {
|
||||||
? needle.slice(1,-1)
|
return new RegExp(needle.slice(1,-1));
|
||||||
: needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
}
|
||||||
}
|
return new RegExp(needle.replace(reRegexEscape, '\\$&'));
|
||||||
|
})();
|
||||||
|
const context = '{{3}}';
|
||||||
|
const reContext = (( ) => {
|
||||||
|
if ( context === '' || context === '{{3}}' ) { return /^$/; }
|
||||||
|
if ( /^\/.+\/$/.test(context) ) {
|
||||||
|
return new RegExp(context.slice(1,-1));
|
||||||
|
}
|
||||||
|
return new RegExp(context.replace(reRegexEscape, '\\$&'));
|
||||||
|
})();
|
||||||
const thisScript = document.currentScript;
|
const thisScript = document.currentScript;
|
||||||
const re = new RegExp(reText);
|
const re = new RegExp(reText);
|
||||||
const chain = target.split('.');
|
const chain = target.split('.');
|
||||||
@ -70,7 +82,7 @@
|
|||||||
const e = document.currentScript;
|
const e = document.currentScript;
|
||||||
if (
|
if (
|
||||||
e instanceof HTMLScriptElement &&
|
e instanceof HTMLScriptElement &&
|
||||||
e.src === '' &&
|
reContext.test(e.src) &&
|
||||||
e !== thisScript &&
|
e !== thisScript &&
|
||||||
re.test(e.textContent)
|
re.test(e.textContent)
|
||||||
) {
|
) {
|
||||||
|
Loading…
Reference in New Issue
Block a user