mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-16 23:42:39 +01:00
Compare commits
No commits in common. "88065d0091cb3c69861501dcdf81ec8dff09e433" and "5dd59889b9eae9ef9fb64761dc4f2dd086d448ac" have entirely different histories.
88065d0091
...
5dd59889b9
@ -276,7 +276,7 @@ function registerProcedural(context) {
|
|||||||
allFrames: true,
|
allFrames: true,
|
||||||
matches,
|
matches,
|
||||||
excludeMatches,
|
excludeMatches,
|
||||||
runAt: 'document_start',
|
runAt: 'document_end',
|
||||||
};
|
};
|
||||||
|
|
||||||
// register
|
// register
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
/* jshint esversion:11 */
|
/* jshint esversion:11 */
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// Important!
|
// Important!
|
||||||
@ -110,21 +112,18 @@ const uBOL_injectCSS = (css, count = 10) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const nonVisualElements = {
|
const nonVisualElements = {
|
||||||
head: true,
|
|
||||||
link: true,
|
|
||||||
meta: true,
|
|
||||||
script: true,
|
script: true,
|
||||||
style: true,
|
style: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const regexFromString = (s, exact = false) => {
|
const regexFromString = (s, exact = false) => {
|
||||||
if ( s === '' ) { return /^/; }
|
if ( s === '' ) { return /^/; }
|
||||||
const match = /^\/(.+)\/([imu]*)$/.exec(s);
|
const match = /^\/(.+)\/([i]?)$/.exec(s);
|
||||||
if ( match !== null ) {
|
if ( match !== null ) {
|
||||||
return new RegExp(match[1], match[2] || undefined);
|
return new RegExp(match[1], match[2] || undefined);
|
||||||
}
|
}
|
||||||
const reStr = s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
const reStr = s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
return new RegExp(exact ? `^${reStr}$` : reStr);
|
return new RegExp(exact ? `^${reStr}$` : reStr, 'i');
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -270,32 +269,6 @@ class PSelectorMatchesPathTask extends PSelectorTask {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
class PSelectorMatchesPropTask extends PSelectorTask {
|
|
||||||
constructor(task) {
|
|
||||||
super();
|
|
||||||
this.props = task[1].attr.split('.');
|
|
||||||
this.reValue = task[1].value !== ''
|
|
||||||
? regexFromString(task[1].value, true)
|
|
||||||
: null;
|
|
||||||
}
|
|
||||||
transpose(node, output) {
|
|
||||||
let value = node;
|
|
||||||
for ( const prop of this.props ) {
|
|
||||||
if ( value === undefined ) { return; }
|
|
||||||
if ( value === null ) { return; }
|
|
||||||
value = value[prop];
|
|
||||||
}
|
|
||||||
if ( this.reValue === null ) {
|
|
||||||
if ( value === undefined ) { return; }
|
|
||||||
} else if ( this.reValue.test(value) === false ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
output.push(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
class PSelectorMinTextLengthTask extends PSelectorTask {
|
class PSelectorMinTextLengthTask extends PSelectorTask {
|
||||||
constructor(task) {
|
constructor(task) {
|
||||||
super();
|
super();
|
||||||
@ -322,28 +295,29 @@ class PSelectorOthersTask extends PSelectorTask {
|
|||||||
const toKeep = new Set(this.targets);
|
const toKeep = new Set(this.targets);
|
||||||
const toDiscard = new Set();
|
const toDiscard = new Set();
|
||||||
const body = document.body;
|
const body = document.body;
|
||||||
const head = document.head;
|
|
||||||
let discard = null;
|
let discard = null;
|
||||||
for ( let keep of this.targets ) {
|
for ( let keep of this.targets ) {
|
||||||
while ( keep !== null && keep !== body && keep !== head ) {
|
while ( keep !== null && keep !== body ) {
|
||||||
toKeep.add(keep);
|
toKeep.add(keep);
|
||||||
toDiscard.delete(keep);
|
toDiscard.delete(keep);
|
||||||
discard = keep.previousElementSibling;
|
discard = keep.previousElementSibling;
|
||||||
while ( discard !== null ) {
|
while ( discard !== null ) {
|
||||||
if ( nonVisualElements[discard.localName] !== true ) {
|
if (
|
||||||
if ( toKeep.has(discard) === false ) {
|
nonVisualElements[discard.localName] !== true &&
|
||||||
|
toKeep.has(discard) === false
|
||||||
|
) {
|
||||||
toDiscard.add(discard);
|
toDiscard.add(discard);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
discard = discard.previousElementSibling;
|
discard = discard.previousElementSibling;
|
||||||
}
|
}
|
||||||
discard = keep.nextElementSibling;
|
discard = keep.nextElementSibling;
|
||||||
while ( discard !== null ) {
|
while ( discard !== null ) {
|
||||||
if ( nonVisualElements[discard.localName] !== true ) {
|
if (
|
||||||
if ( toKeep.has(discard) === false ) {
|
nonVisualElements[discard.localName] !== true &&
|
||||||
|
toKeep.has(discard) === false
|
||||||
|
) {
|
||||||
toDiscard.add(discard);
|
toDiscard.add(discard);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
discard = discard.nextElementSibling;
|
discard = discard.nextElementSibling;
|
||||||
}
|
}
|
||||||
keep = keep.parentElement;
|
keep = keep.parentElement;
|
||||||
@ -596,7 +570,6 @@ PSelector.prototype.operatorToTaskMap = new Map([
|
|||||||
[ 'matches-css-before', PSelectorMatchesCSSBeforeTask ],
|
[ 'matches-css-before', PSelectorMatchesCSSBeforeTask ],
|
||||||
[ 'matches-media', PSelectorMatchesMediaTask ],
|
[ 'matches-media', PSelectorMatchesMediaTask ],
|
||||||
[ 'matches-path', PSelectorMatchesPathTask ],
|
[ 'matches-path', PSelectorMatchesPathTask ],
|
||||||
[ 'matches-prop', PSelectorMatchesPropTask ],
|
|
||||||
[ 'min-text-length', PSelectorMinTextLengthTask ],
|
[ 'min-text-length', PSelectorMinTextLengthTask ],
|
||||||
[ 'not', PSelectorIfNotTask ],
|
[ 'not', PSelectorIfNotTask ],
|
||||||
[ 'others', PSelectorOthersTask ],
|
[ 'others', PSelectorOthersTask ],
|
||||||
|
Loading…
Reference in New Issue
Block a user