mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-16 15:33:38 +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,
|
||||
matches,
|
||||
excludeMatches,
|
||||
runAt: 'document_start',
|
||||
runAt: 'document_end',
|
||||
};
|
||||
|
||||
// register
|
||||
|
@ -21,6 +21,8 @@
|
||||
|
||||
/* jshint esversion:11 */
|
||||
|
||||
'use strict';
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Important!
|
||||
@ -110,21 +112,18 @@ const uBOL_injectCSS = (css, count = 10) => {
|
||||
};
|
||||
|
||||
const nonVisualElements = {
|
||||
head: true,
|
||||
link: true,
|
||||
meta: true,
|
||||
script: true,
|
||||
style: true,
|
||||
};
|
||||
|
||||
const regexFromString = (s, exact = false) => {
|
||||
if ( s === '' ) { return /^/; }
|
||||
const match = /^\/(.+)\/([imu]*)$/.exec(s);
|
||||
const match = /^\/(.+)\/([i]?)$/.exec(s);
|
||||
if ( match !== null ) {
|
||||
return new RegExp(match[1], match[2] || undefined);
|
||||
}
|
||||
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 {
|
||||
constructor(task) {
|
||||
super();
|
||||
@ -322,28 +295,29 @@ class PSelectorOthersTask extends PSelectorTask {
|
||||
const toKeep = new Set(this.targets);
|
||||
const toDiscard = new Set();
|
||||
const body = document.body;
|
||||
const head = document.head;
|
||||
let discard = null;
|
||||
for ( let keep of this.targets ) {
|
||||
while ( keep !== null && keep !== body && keep !== head ) {
|
||||
while ( keep !== null && keep !== body ) {
|
||||
toKeep.add(keep);
|
||||
toDiscard.delete(keep);
|
||||
discard = keep.previousElementSibling;
|
||||
while ( discard !== null ) {
|
||||
if ( nonVisualElements[discard.localName] !== true ) {
|
||||
if ( toKeep.has(discard) === false ) {
|
||||
if (
|
||||
nonVisualElements[discard.localName] !== true &&
|
||||
toKeep.has(discard) === false
|
||||
) {
|
||||
toDiscard.add(discard);
|
||||
}
|
||||
}
|
||||
discard = discard.previousElementSibling;
|
||||
}
|
||||
discard = keep.nextElementSibling;
|
||||
while ( discard !== null ) {
|
||||
if ( nonVisualElements[discard.localName] !== true ) {
|
||||
if ( toKeep.has(discard) === false ) {
|
||||
if (
|
||||
nonVisualElements[discard.localName] !== true &&
|
||||
toKeep.has(discard) === false
|
||||
) {
|
||||
toDiscard.add(discard);
|
||||
}
|
||||
}
|
||||
discard = discard.nextElementSibling;
|
||||
}
|
||||
keep = keep.parentElement;
|
||||
@ -596,7 +570,6 @@ PSelector.prototype.operatorToTaskMap = new Map([
|
||||
[ 'matches-css-before', PSelectorMatchesCSSBeforeTask ],
|
||||
[ 'matches-media', PSelectorMatchesMediaTask ],
|
||||
[ 'matches-path', PSelectorMatchesPathTask ],
|
||||
[ 'matches-prop', PSelectorMatchesPropTask ],
|
||||
[ 'min-text-length', PSelectorMinTextLengthTask ],
|
||||
[ 'not', PSelectorIfNotTask ],
|
||||
[ 'others', PSelectorOthersTask ],
|
||||
|
Loading…
Reference in New Issue
Block a user