mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-15 07:22:28 +02:00
code reviewed implementation of high-medium generic cosmetic filters
This commit is contained in:
parent
032becfd76
commit
59bdcbdb7e
@ -93,7 +93,7 @@ return {
|
|||||||
|
|
||||||
// read-only
|
// read-only
|
||||||
systemSettings: {
|
systemSettings: {
|
||||||
compiledMagic: 'rzohdugizuxh',
|
compiledMagic: 'wzwgqiwgjhsh',
|
||||||
selfieMagic: 'mnigwksyvgkv'
|
selfieMagic: 'mnigwksyvgkv'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -577,19 +577,39 @@ var uBlockCollapser = (function() {
|
|||||||
var nodeList = selectNodes('a[href^="http"]');
|
var nodeList = selectNodes('a[href^="http"]');
|
||||||
var iNode = nodeList.length;
|
var iNode = nodeList.length;
|
||||||
var node, href, pos, hash, selectors, selector, iSelector;
|
var node, href, pos, hash, selectors, selector, iSelector;
|
||||||
|
|
||||||
while ( iNode-- ) {
|
while ( iNode-- ) {
|
||||||
node = nodeList[iNode];
|
node = nodeList[iNode];
|
||||||
href = node.getAttribute('href');
|
href = node.getAttribute('href');
|
||||||
if ( !href ) { continue; }
|
if ( !href ) { continue; }
|
||||||
|
|
||||||
pos = href.indexOf('://');
|
pos = href.indexOf('://');
|
||||||
if ( pos === -1 ) { continue; }
|
if ( pos === -1 ) { continue; }
|
||||||
|
|
||||||
hash = href.slice(pos + 3, pos + 11);
|
hash = href.slice(pos + 3, pos + 11);
|
||||||
selectors = generics[hash];
|
selectors = generics[hash];
|
||||||
if ( selectors === undefined ) { continue; }
|
if ( selectors === undefined ) { continue; }
|
||||||
|
|
||||||
|
// A string.
|
||||||
|
if ( typeof selectors === 'string' ) {
|
||||||
|
if (
|
||||||
|
href.lastIndexOf(selectors.slice(8, -2), 0) === 0 &&
|
||||||
|
injectedSelectors.hasOwnProperty(selectors) === false
|
||||||
|
) {
|
||||||
|
injectedSelectors[selectors] = true;
|
||||||
|
out.push(selectors);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// An array of strings.
|
||||||
iSelector = selectors.length;
|
iSelector = selectors.length;
|
||||||
while ( iSelector-- ) {
|
while ( iSelector-- ) {
|
||||||
selector = selectors[iSelector];
|
selector = selectors[iSelector];
|
||||||
if ( injectedSelectors.hasOwnProperty(selector) === false ) {
|
if (
|
||||||
|
href.lastIndexOf(selector.slice(8, -2), 0) === 0 &&
|
||||||
|
injectedSelectors.hasOwnProperty(selector) === false
|
||||||
|
) {
|
||||||
injectedSelectors[selector] = true;
|
injectedSelectors[selector] = true;
|
||||||
out.push(selector);
|
out.push(selector);
|
||||||
}
|
}
|
||||||
|
@ -769,7 +769,7 @@ FilterContainer.prototype.fromCompiledContent = function(text, lineBeg, skip) {
|
|||||||
|
|
||||||
var lineEnd;
|
var lineEnd;
|
||||||
var textEnd = text.length;
|
var textEnd = text.length;
|
||||||
var line, fields, filter, bucket;
|
var line, fields, filter, key, bucket;
|
||||||
|
|
||||||
while ( lineBeg < textEnd ) {
|
while ( lineBeg < textEnd ) {
|
||||||
if ( text.charAt(lineBeg) !== 'c' ) {
|
if ( text.charAt(lineBeg) !== 'c' ) {
|
||||||
@ -841,10 +841,14 @@ FilterContainer.prototype.fromCompiledContent = function(text, lineBeg, skip) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( fields[0] === 'hmg0' ) {
|
if ( fields[0] === 'hmg0' ) {
|
||||||
if ( Array.isArray(this.highMediumGenericHide[fields[1]]) ) {
|
key = fields[1];
|
||||||
this.highMediumGenericHide[fields[1]].push(fields[2]);
|
bucket = this.highMediumGenericHide[key];
|
||||||
|
if ( bucket === undefined ) {
|
||||||
|
this.highMediumGenericHide[key] = fields[2];
|
||||||
|
} else if ( Array.isArray(bucket) ) {
|
||||||
|
bucket.push(fields[2]);
|
||||||
} else {
|
} else {
|
||||||
this.highMediumGenericHide[fields[1]] = [fields[2]];
|
this.highMediumGenericHide[key] = [bucket, fields[2]];
|
||||||
}
|
}
|
||||||
this.highMediumGenericHideCount += 1;
|
this.highMediumGenericHideCount += 1;
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user