aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgorhill <rhill@raymondhill.net>2015-09-11 17:59:25 -0400
committergorhill <rhill@raymondhill.net>2015-09-11 17:59:25 -0400
commit59bdcbdb7e8ac788ed07c909606b7f9b31be1500 (patch)
tree9347cd2cbfc37b3d4a8a0ee1d5c645f49457f80d
parent032becfd76f43c2c25fe18df6c85044ccccb5c6b (diff)
downloaduBlock-59bdcbdb7e8ac788ed07c909606b7f9b31be1500.zip
uBlock-59bdcbdb7e8ac788ed07c909606b7f9b31be1500.tar.gz
uBlock-59bdcbdb7e8ac788ed07c909606b7f9b31be1500.tar.bz2
code reviewed implementation of high-medium generic cosmetic filters
-rw-r--r--src/js/background.js2
-rw-r--r--src/js/contentscript-end.js22
-rw-r--r--src/js/cosmetic-filtering.js12
3 files changed, 30 insertions, 6 deletions
diff --git a/src/js/background.js b/src/js/background.js
index 8cb846d..5da45ac 100644
--- a/src/js/background.js
+++ b/src/js/background.js
@@ -93,7 +93,7 @@ return {
// read-only
systemSettings: {
- compiledMagic: 'rzohdugizuxh',
+ compiledMagic: 'wzwgqiwgjhsh',
selfieMagic: 'mnigwksyvgkv'
},
diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js
index c12ff7b..b4cd920 100644
--- a/src/js/contentscript-end.js
+++ b/src/js/contentscript-end.js
@@ -577,19 +577,39 @@ var uBlockCollapser = (function() {
var nodeList = selectNodes('a[href^="http"]');
var iNode = nodeList.length;
var node, href, pos, hash, selectors, selector, iSelector;
+
while ( iNode-- ) {
node = nodeList[iNode];
href = node.getAttribute('href');
if ( !href ) { continue; }
+
pos = href.indexOf('://');
if ( pos === -1 ) { continue; }
+
hash = href.slice(pos + 3, pos + 11);
selectors = generics[hash];
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;
while ( 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;
out.push(selector);
}
diff --git a/src/js/cosmetic-filtering.js b/src/js/cosmetic-filtering.js
index fd51c22..fa6214a 100644
--- a/src/js/cosmetic-filtering.js
+++ b/src/js/cosmetic-filtering.js
@@ -769,7 +769,7 @@ FilterContainer.prototype.fromCompiledContent = function(text, lineBeg, skip) {
var lineEnd;
var textEnd = text.length;
- var line, fields, filter, bucket;
+ var line, fields, filter, key, bucket;
while ( lineBeg < textEnd ) {
if ( text.charAt(lineBeg) !== 'c' ) {
@@ -841,10 +841,14 @@ FilterContainer.prototype.fromCompiledContent = function(text, lineBeg, skip) {
}
if ( fields[0] === 'hmg0' ) {
- if ( Array.isArray(this.highMediumGenericHide[fields[1]]) ) {
- this.highMediumGenericHide[fields[1]].push(fields[2]);
+ key = fields[1];
+ bucket = this.highMediumGenericHide[key];
+ if ( bucket === undefined ) {
+ this.highMediumGenericHide[key] = fields[2];
+ } else if ( Array.isArray(bucket) ) {
+ bucket.push(fields[2]);
} else {
- this.highMediumGenericHide[fields[1]] = [fields[2]];
+ this.highMediumGenericHide[key] = [bucket, fields[2]];
}
this.highMediumGenericHideCount += 1;
continue;