Skip to content

Commit 0240190

Browse files
committed
Fix specifichide option
Related internal feedback: uBlockOrigin/uBlock-discussions#964
1 parent 9cf8a0f commit 0240190

File tree

1 file changed

+35
-38
lines changed

1 file changed

+35
-38
lines changed

src/js/cosmetic-filtering.js

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,9 @@ CosmeticFilteringEngine.prototype.retrieveSpecificSelectors = function(
758758
disableSurveyor: this.lowlyGeneric.size === 0,
759759
};
760760
const injectedCSS = [];
761+
const exceptionSet = new Set();
761762

762-
if (
763-
options.noSpecificCosmeticFiltering !== true ||
764-
options.noGenericCosmeticFiltering !== true
765-
) {
763+
if ( options.noSpecificCosmeticFiltering !== true ) {
766764
// Cached cosmetic filters: these are always declarative.
767765
const specificSet = new Set();
768766
if ( cacheEntry !== undefined ) {
@@ -785,7 +783,6 @@ CosmeticFilteringEngine.prototype.retrieveSpecificSelectors = function(
785783

786784
// Split filters in different groups
787785
const proceduralSet = new Set();
788-
const exceptionSet = new Set();
789786
for ( const s of allSet ) {
790787
const selector = s.slice(1);
791788
if ( s.charCodeAt(0) === 0x2D /* - */ ) {
@@ -837,44 +834,44 @@ CosmeticFilteringEngine.prototype.retrieveSpecificSelectors = function(
837834
}
838835
out.proceduralFilters.push(...proceduralSet);
839836
}
837+
}
840838

841-
// Highly generic cosmetic filters: sent once along with specific ones.
842-
// A most-recent-used cache is used to skip computing the resulting set
843-
// of high generics for a given set of exceptions.
844-
// The resulting set of high generics is stored as a string, ready to
845-
// be used as-is by the content script. The string is stored
846-
// indirectly in the mru cache: this is to prevent duplication of the
847-
// string in memory, which I have observed occurs when the string is
848-
// stored directly as a value in a Map.
849-
if ( options.noGenericCosmeticFiltering !== true ) {
850-
const exceptionSetHash = out.exceptionFilters.join();
851-
for ( const key in this.highlyGeneric ) {
852-
const entry = this.highlyGeneric[key];
853-
let str = entry.mru.lookup(exceptionSetHash);
854-
if ( str === undefined ) {
855-
str = { s: entry.str, excepted: [] };
856-
let genericSet = entry.dict;
857-
let hit = false;
839+
// Highly generic cosmetic filters: sent once along with specific ones.
840+
// A most-recent-used cache is used to skip computing the resulting set
841+
// of high generics for a given set of exceptions.
842+
// The resulting set of high generics is stored as a string, ready to
843+
// be used as-is by the content script. The string is stored
844+
// indirectly in the mru cache: this is to prevent duplication of the
845+
// string in memory, which I have observed occurs when the string is
846+
// stored directly as a value in a Map.
847+
if ( options.noGenericCosmeticFiltering !== true ) {
848+
const exceptionSetHash = out.exceptionFilters.join();
849+
for ( const key in this.highlyGeneric ) {
850+
const entry = this.highlyGeneric[key];
851+
let str = entry.mru.lookup(exceptionSetHash);
852+
if ( str === undefined ) {
853+
str = { s: entry.str, excepted: [] };
854+
let genericSet = entry.dict;
855+
let hit = false;
856+
for ( const exception of exceptionSet ) {
857+
if ( (hit = genericSet.has(exception)) ) { break; }
858+
}
859+
if ( hit ) {
860+
genericSet = new Set(entry.dict);
858861
for ( const exception of exceptionSet ) {
859-
if ( (hit = genericSet.has(exception)) ) { break; }
860-
}
861-
if ( hit ) {
862-
genericSet = new Set(entry.dict);
863-
for ( const exception of exceptionSet ) {
864-
if ( genericSet.delete(exception) ) {
865-
str.excepted.push(exception);
866-
}
862+
if ( genericSet.delete(exception) ) {
863+
str.excepted.push(exception);
867864
}
868-
str.s = Array.from(genericSet).join(',\n');
869865
}
870-
entry.mru.add(exceptionSetHash, str);
871-
}
872-
if ( str.excepted.length !== 0 ) {
873-
out.exceptedFilters.push(...str.excepted);
874-
}
875-
if ( str.s.length !== 0 ) {
876-
injectedCSS.push(`${str.s}\n{display:none!important;}`);
866+
str.s = Array.from(genericSet).join(',\n');
877867
}
868+
entry.mru.add(exceptionSetHash, str);
869+
}
870+
if ( str.excepted.length !== 0 ) {
871+
out.exceptedFilters.push(...str.excepted);
872+
}
873+
if ( str.s.length !== 0 ) {
874+
injectedCSS.push(`${str.s}\n{display:none!important;}`);
878875
}
879876
}
880877
}

0 commit comments

Comments
 (0)