Skip to content
This repository was archived by the owner on Nov 15, 2017. It is now read-only.

Commit 93725cb

Browse files
committed
this fixes #276
1 parent 43294f8 commit 93725cb

File tree

2 files changed

+55
-15
lines changed

2 files changed

+55
-15
lines changed

js/abp-hide-filters.js

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ var FilterContainer = function() {
241241
this.acceptedCount = 0;
242242
this.processedCount = 0;
243243
this.filters = {};
244+
this.rejected = [];
244245
};
245246

246247
/******************************************************************************/
@@ -252,6 +253,9 @@ FilterContainer.prototype.reset = function() {
252253
this.acceptedCount = 0;
253254
this.processedCount = 0;
254255
this.filters = {};
256+
this.hideUnfiltered = [];
257+
this.donthideUnfiltered = [];
258+
this.rejected = [];
255259
};
256260

257261
/******************************************************************************/
@@ -289,21 +293,44 @@ FilterContainer.prototype.add = function(s) {
289293
// Content script side, the unsorted container of selectors could be used
290294
// in a querySelectorAll() to figure which rules apply (if any), or they
291295
// could just all be injected undiscriminately (not good).
292-
if ( parsed.isElement() ) {
293-
return this.addElementFilter(parsed);
296+
if ( parsed.filterType === '#' ) {
297+
this.hideUnfiltered.push(parsed.suffix);
298+
} else {
299+
this.donthideUnfiltered.push(parsed.suffix);
294300
}
301+
this.acceptedCount += 1;
295302

296-
return false;
303+
return true;
304+
};
305+
306+
/******************************************************************************/
307+
308+
FilterContainer.prototype.chunkify = function(selectors) {
309+
var chunkified = [], chunk;
310+
for (;;) {
311+
chunk = selectors.splice(0, 10);
312+
if ( chunk.length === 0 ) {
313+
break;
314+
}
315+
chunkified.push(chunk.join(','));
316+
}
317+
return chunkified;
297318
};
298319

299320
/******************************************************************************/
300321

301322
FilterContainer.prototype.freeze = function() {
323+
this.hideUnfiltered = this.chunkify(this.hideUnfiltered);
324+
this.donthideUnfiltered = this.chunkify(this.donthideUnfiltered);
325+
302326
this.filterParser.reset();
303327

304328
console.log('HTTPSB> adp-hide-filters.js: %d filters accepted', this.acceptedCount);
305329
console.log('HTTPSB> adp-hide-filters.js: %d filters processed', this.processedCount);
306330
console.log('HTTPSB> adp-hide-filters.js: coverage is %s%', (this.acceptedCount * 100 / this.processedCount).toFixed(1));
331+
console.log('HTTPSB> adp-hide-filters.js: unfiltered hide selectors:', this.hideUnfiltered);
332+
console.log('HTTPSB> adp-hide-filters.js: unfiltered dont hide selectors:', this.donthideUnfiltered);
333+
console.log('HTTPSB> adp-hide-filters.js: rejected selectors:', this.rejected);
307334

308335
//histogram('allFilters', this.filters);
309336
};
@@ -436,12 +463,12 @@ FilterContainer.prototype.addPlainFilter = function(parsed) {
436463
/******************************************************************************/
437464

438465
FilterContainer.prototype.addPlainMoreFilter = function(parsed) {
439-
var plainSelector = parsed.extractPlain();
440-
if ( plainSelector === '' ) {
466+
var selectorSuffix = parsed.extractPlain();
467+
if ( selectorSuffix === '' ) {
441468
return;
442469
}
443470
var f = new FilterPlainMore(parsed.suffix);
444-
var hash = makeSuffixHash(parsed.filterType, plainSelector);
471+
var hash = makeSuffixHash(parsed.filterType, selectorSuffix);
445472
this.addFilterEntry(hash, f);
446473
this.acceptedCount += 1;
447474
};
@@ -469,11 +496,6 @@ FilterContainer.prototype.addHostnameFilter = function(parsed) {
469496

470497
/******************************************************************************/
471498

472-
FilterContainer.prototype.addElementFilter = function(parsed) {
473-
};
474-
475-
/******************************************************************************/
476-
477499
FilterContainer.prototype.addFilterEntry = function(hash, f) {
478500
var bucket = this.filters[hash];
479501
if ( bucket === undefined ) {
@@ -543,7 +565,9 @@ FilterContainer.prototype.retrieve = function(url, inSelectors) {
543565

544566
return {
545567
hide: hideSelectors,
546-
donthide: donthideSelectors
568+
donthide: donthideSelectors,
569+
hideUnfiltered: this.hideUnfiltered,
570+
donthideUnfiltered: this.donthideUnfiltered
547571
};
548572
};
549573

js/contentscript.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ CosmeticFiltering.prototype.retrieve = function() {
5252
selectors = selectors.concat(this.idSelectors);
5353
}
5454
if ( selectors.length > 0 ) {
55-
// console.log('HTTPSB> ABP cosmetic filters: retrieving CSS rules using %d selectors (%o)', selectors.length, selectors);
55+
//console.log('HTTPSB> ABP cosmetic filters: retrieving CSS rules using %d selectors', selectors.length);
5656
chrome.runtime.sendMessage({
5757
what: 'retrieveABPHideSelectors',
5858
selectors: selectors,
@@ -68,16 +68,18 @@ CosmeticFiltering.prototype.retrieveHandler = function(selectors) {
6868
return;
6969
}
7070
var styleText = [];
71+
this.filterUnfiltered(selectors.hideUnfiltered, selectors.hide);
7172
this.reduce(selectors.hide, this.injectedSelectors);
7273
if ( selectors.hide.length ) {
73-
var hideStyleText = '{{hideSelectors}} {display:none;}'
74+
var hideStyleText = '{{hideSelectors}} {display:none; !important}'
7475
.replace('{{hideSelectors}}', selectors.hide.join(','));
7576
styleText.push(hideStyleText);
7677
//console.log('HTTPSB> ABP cosmetic filters: injecting %d CSS rules:', selectors.hide.length, hideStyleText);
7778
}
79+
this.filterUnfiltered(selectors.donthideUnfiltered, selectors.donthide);
7880
this.reduce(selectors.donthide, this.injectedSelectors);
7981
if ( selectors.donthide.length ) {
80-
var dontHideStyleText = '{{donthideSelectors}} {display:initial;}'
82+
var dontHideStyleText = '{{donthideSelectors}} {display:initial; !important}'
8183
.replace('{{donthideSelectors}}', selectors.donthide.join(','));
8284
styleText.push(dontHideStyleText);
8385
//console.log('HTTPSB> ABP cosmetic filters: injecting %d CSS rules:', selectors.donthide.length, dontHideStyleText);
@@ -89,6 +91,20 @@ CosmeticFiltering.prototype.retrieveHandler = function(selectors) {
8991
}
9092
};
9193

94+
CosmeticFiltering.prototype.filterUnfiltered = function(inSelectors, outSelectors) {
95+
var i = inSelectors.length;
96+
var selector;
97+
while ( i-- ) {
98+
selector = inSelectors[i];
99+
if ( this.injectedSelectors[selector] ) {
100+
continue;
101+
}
102+
if ( document.querySelector(selector) !== null ) {
103+
outSelectors.push(selector);
104+
}
105+
}
106+
};
107+
92108
CosmeticFiltering.prototype.reduce = function(selectors, dict) {
93109
var first = dict.httpsb === undefined;
94110
var i = selectors.length, selector, end;

0 commit comments

Comments
 (0)