mirror of https://github.com/gorhill/uBlock.git
code review: no need to distinguish generic exception filters
This commit is contained in:
parent
57274ac726
commit
6a523656c3
|
@ -88,7 +88,7 @@ return {
|
||||||
|
|
||||||
// read-only
|
// read-only
|
||||||
systemSettings: {
|
systemSettings: {
|
||||||
compiledMagic: 'emkzqkaljcfd',
|
compiledMagic: 'intdliecolot',
|
||||||
selfieMagic: 'spqmeuaftfra'
|
selfieMagic: 'spqmeuaftfra'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -163,18 +163,6 @@ var messager = vAPI.messaging.channel('contentscript-end.js');
|
||||||
if ( selectors && selectors.donthide.length ) {
|
if ( selectors && selectors.donthide.length ) {
|
||||||
processLowGenerics(selectors.donthide, nullArray);
|
processLowGenerics(selectors.donthide, nullArray);
|
||||||
}
|
}
|
||||||
if ( highGenerics ) {
|
|
||||||
if ( highGenerics.donthideLowCount ) {
|
|
||||||
processHighLowGenerics(highGenerics.donthideLow, nullArray);
|
|
||||||
}
|
|
||||||
if ( highGenerics.donthideMediumCount ) {
|
|
||||||
processHighMediumGenerics(highGenerics.donthideMedium, nullArray);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// No such thing as high-high generic exceptions.
|
|
||||||
//if ( highGenerics.donthideHighCount ) {
|
|
||||||
// processHighHighGenerics(document, highGenerics.donthideHigh, nullArray);
|
|
||||||
//}
|
|
||||||
var hideSelectors = [];
|
var hideSelectors = [];
|
||||||
if ( selectors && selectors.hide.length ) {
|
if ( selectors && selectors.hide.length ) {
|
||||||
processLowGenerics(selectors.hide, hideSelectors);
|
processLowGenerics(selectors.hide, hideSelectors);
|
||||||
|
|
|
@ -533,31 +533,26 @@ FilterContainer.prototype.reset = function() {
|
||||||
// permanent
|
// permanent
|
||||||
// [class], [id]
|
// [class], [id]
|
||||||
this.lowGenericHide = {};
|
this.lowGenericHide = {};
|
||||||
this.lowGenericDonthide = [];
|
|
||||||
|
|
||||||
// [alt="..."], [title="..."]
|
// [alt="..."], [title="..."]
|
||||||
this.highLowGenericHide = {};
|
this.highLowGenericHide = {};
|
||||||
this.highLowGenericDonthide = {};
|
|
||||||
this.highLowGenericHideCount = 0;
|
this.highLowGenericHideCount = 0;
|
||||||
this.highLowGenericDonthideCount = 0;
|
|
||||||
|
|
||||||
// a[href^="http..."]
|
// a[href^="http..."]
|
||||||
this.highMediumGenericHide = {};
|
this.highMediumGenericHide = {};
|
||||||
this.highMediumGenericDonthide = {};
|
|
||||||
this.highMediumGenericHideCount = 0;
|
this.highMediumGenericHideCount = 0;
|
||||||
this.highMediumGenericDonthideCount = 0;
|
|
||||||
|
|
||||||
// everything else
|
// everything else
|
||||||
this.highHighGenericHideArray = [];
|
this.highHighGenericHideArray = [];
|
||||||
this.highHighGenericHide = '';
|
this.highHighGenericHide = '';
|
||||||
this.highHighGenericHideCount = 0;
|
this.highHighGenericHideCount = 0;
|
||||||
this.highHighGenericDonthideArray = [];
|
|
||||||
this.highHighGenericDonthide = '';
|
|
||||||
this.highHighGenericDonthideCount = 0;
|
|
||||||
|
|
||||||
// hostname, entity-based filters
|
// hostname, entity-based filters
|
||||||
this.hostnameFilters = {};
|
this.hostnameFilters = {};
|
||||||
this.entityFilters = {};
|
this.entityFilters = {};
|
||||||
|
|
||||||
|
// generic exception filters
|
||||||
|
this.genericDonthide = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@ -626,7 +621,7 @@ FilterContainer.prototype.compileGenericSelector = function(parsed, out) {
|
||||||
out.push(
|
out.push(
|
||||||
'c\v' +
|
'c\v' +
|
||||||
(matches[1] === selector ? 'lg\v' : 'lg+\v') +
|
(matches[1] === selector ? 'lg\v' : 'lg+\v') +
|
||||||
makeHash(parsed.unhide, matches[1], this.genericHashMask) + '\v' +
|
makeHash(0, matches[1], this.genericHashMask) + '\v' +
|
||||||
selector
|
selector
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
|
@ -636,7 +631,7 @@ FilterContainer.prototype.compileGenericSelector = function(parsed, out) {
|
||||||
if ( this.reHighLow.test(selector) ) {
|
if ( this.reHighLow.test(selector) ) {
|
||||||
out.push(
|
out.push(
|
||||||
'c\v' +
|
'c\v' +
|
||||||
(parsed.unhide === 0 ? 'hlg0\v' : 'hlg1\v') +
|
'hlg0\v' +
|
||||||
selector
|
selector
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
|
@ -647,7 +642,7 @@ FilterContainer.prototype.compileGenericSelector = function(parsed, out) {
|
||||||
if ( matches && matches.length === 2 ) {
|
if ( matches && matches.length === 2 ) {
|
||||||
out.push(
|
out.push(
|
||||||
'c\v' +
|
'c\v' +
|
||||||
(parsed.unhide === 0 ? 'hmg0\v' : 'hmg1\v') +
|
'hmg0\v' +
|
||||||
matches[1] + '\v' +
|
matches[1] + '\v' +
|
||||||
selector
|
selector
|
||||||
);
|
);
|
||||||
|
@ -657,7 +652,7 @@ FilterContainer.prototype.compileGenericSelector = function(parsed, out) {
|
||||||
// All else
|
// All else
|
||||||
out.push(
|
out.push(
|
||||||
'c\v' +
|
'c\v' +
|
||||||
(parsed.unhide === 0 ? 'hhg0\v' : 'hhg1\v') +
|
'hhg0\v' +
|
||||||
selector
|
selector
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -785,12 +780,6 @@ FilterContainer.prototype.fromCompiledContent = function(text, lineBeg, skip) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fields[0] === 'hlg1' ) {
|
|
||||||
this.highLowGenericDonthide[fields[1]] = true;
|
|
||||||
this.highLowGenericDonthideCount += 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( fields[0] === 'hmg0' ) {
|
if ( fields[0] === 'hmg0' ) {
|
||||||
if ( Array.isArray(this.highMediumGenericHide[fields[1]]) ) {
|
if ( Array.isArray(this.highMediumGenericHide[fields[1]]) ) {
|
||||||
this.highMediumGenericHide[fields[1]].push(fields[2]);
|
this.highMediumGenericHide[fields[1]].push(fields[2]);
|
||||||
|
@ -801,32 +790,16 @@ FilterContainer.prototype.fromCompiledContent = function(text, lineBeg, skip) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fields[0] === 'hmg1' ) {
|
|
||||||
if ( Array.isArray(this.highMediumGenericDonthide[fields[1]]) ) {
|
|
||||||
this.highMediumGenericDonthide[fields[1]].push(fields[2]);
|
|
||||||
} else {
|
|
||||||
this.highMediumGenericDonthide[fields[1]] = [fields[2]];
|
|
||||||
}
|
|
||||||
this.highMediumGenericDonthideCount += 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( fields[0] === 'hhg0' ) {
|
if ( fields[0] === 'hhg0' ) {
|
||||||
this.highHighGenericHideArray.push(fields[1]);
|
this.highHighGenericHideArray.push(fields[1]);
|
||||||
this.highHighGenericHideCount += 1;
|
this.highHighGenericHideCount += 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fields[0] === 'hhg1' ) {
|
|
||||||
this.highHighGenericDonthideArray.push(fields[1]);
|
|
||||||
this.highHighGenericDonthideCount += 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/gorhill/uBlock/issues/497
|
// https://github.com/gorhill/uBlock/issues/497
|
||||||
// Generic exception filters: expected to be a rare occurrence.
|
// Generic exception filters: expected to be a rare occurrence.
|
||||||
if ( fields[0] === 'g1' ) {
|
if ( fields[0] === 'g1' ) {
|
||||||
this.lowGenericDonthide.push(fields[1]);
|
this.genericDonthide.push(fields[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return textEnd;
|
return textEnd;
|
||||||
|
@ -861,11 +834,6 @@ FilterContainer.prototype.freeze = function() {
|
||||||
}
|
}
|
||||||
this.highHighGenericHide = this.highHighGenericHideArray.join(',\n');
|
this.highHighGenericHide = this.highHighGenericHideArray.join(',\n');
|
||||||
this.highHighGenericHideArray = [];
|
this.highHighGenericHideArray = [];
|
||||||
if ( this.highHighGenericDonthide !== '' ) {
|
|
||||||
this.highHighGenericDonthideArray.unshift(this.highHighGenericDonthide);
|
|
||||||
}
|
|
||||||
this.highHighGenericDonthide = this.highHighGenericDonthideArray.join(',\n');
|
|
||||||
this.highHighGenericDonthideArray = [];
|
|
||||||
|
|
||||||
this.parser.reset();
|
this.parser.reset();
|
||||||
this.frozen = true;
|
this.frozen = true;
|
||||||
|
@ -905,19 +873,13 @@ FilterContainer.prototype.toSelfie = function() {
|
||||||
hostnameSpecificFilters: selfieFromDict(this.hostnameFilters),
|
hostnameSpecificFilters: selfieFromDict(this.hostnameFilters),
|
||||||
entitySpecificFilters: this.entityFilters,
|
entitySpecificFilters: this.entityFilters,
|
||||||
lowGenericHide: selfieFromDict(this.lowGenericHide),
|
lowGenericHide: selfieFromDict(this.lowGenericHide),
|
||||||
lowGenericDonthide: this.lowGenericDonthide,
|
|
||||||
highLowGenericHide: this.highLowGenericHide,
|
highLowGenericHide: this.highLowGenericHide,
|
||||||
highLowGenericDonthide: this.highLowGenericDonthide,
|
|
||||||
highLowGenericHideCount: this.highLowGenericHideCount,
|
highLowGenericHideCount: this.highLowGenericHideCount,
|
||||||
highLowGenericDonthideCount: this.highLowGenericDonthideCount,
|
|
||||||
highMediumGenericHide: this.highMediumGenericHide,
|
highMediumGenericHide: this.highMediumGenericHide,
|
||||||
highMediumGenericDonthide: this.highMediumGenericDonthide,
|
|
||||||
highMediumGenericHideCount: this.highMediumGenericHideCount,
|
highMediumGenericHideCount: this.highMediumGenericHideCount,
|
||||||
highMediumGenericDonthideCount: this.highMediumGenericDonthideCount,
|
|
||||||
highHighGenericHide: this.highHighGenericHide,
|
highHighGenericHide: this.highHighGenericHide,
|
||||||
highHighGenericDonthide: this.highHighGenericDonthide,
|
|
||||||
highHighGenericHideCount: this.highHighGenericHideCount,
|
highHighGenericHideCount: this.highHighGenericHideCount,
|
||||||
highHighGenericDonthideCount: this.highHighGenericDonthideCount
|
genericDonthide: this.genericDonthide
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -971,19 +933,13 @@ FilterContainer.prototype.fromSelfie = function(selfie) {
|
||||||
this.hostnameFilters = dictFromSelfie(selfie.hostnameSpecificFilters);
|
this.hostnameFilters = dictFromSelfie(selfie.hostnameSpecificFilters);
|
||||||
this.entityFilters = selfie.entitySpecificFilters;
|
this.entityFilters = selfie.entitySpecificFilters;
|
||||||
this.lowGenericHide = dictFromSelfie(selfie.lowGenericHide);
|
this.lowGenericHide = dictFromSelfie(selfie.lowGenericHide);
|
||||||
this.lowGenericDonthide = selfie.lowGenericDonthide;
|
|
||||||
this.highLowGenericHide = selfie.highLowGenericHide;
|
this.highLowGenericHide = selfie.highLowGenericHide;
|
||||||
this.highLowGenericDonthide = selfie.highLowGenericDonthide;
|
|
||||||
this.highLowGenericHideCount = selfie.highLowGenericHideCount;
|
this.highLowGenericHideCount = selfie.highLowGenericHideCount;
|
||||||
this.highLowGenericDonthideCount = selfie.highLowGenericDonthideCount;
|
|
||||||
this.highMediumGenericHide = selfie.highMediumGenericHide;
|
this.highMediumGenericHide = selfie.highMediumGenericHide;
|
||||||
this.highMediumGenericDonthide = selfie.highMediumGenericDonthide;
|
|
||||||
this.highMediumGenericHideCount = selfie.highMediumGenericHideCount;
|
this.highMediumGenericHideCount = selfie.highMediumGenericHideCount;
|
||||||
this.highMediumGenericDonthideCount = selfie.highMediumGenericDonthideCount;
|
|
||||||
this.highHighGenericHide = selfie.highHighGenericHide;
|
this.highHighGenericHide = selfie.highHighGenericHide;
|
||||||
this.highHighGenericDonthide = selfie.highHighGenericDonthide;
|
|
||||||
this.highHighGenericHideCount = selfie.highHighGenericHideCount;
|
this.highHighGenericHideCount = selfie.highHighGenericHideCount;
|
||||||
this.highHighGenericDonthideCount = selfie.highHighGenericDonthideCount;
|
this.genericDonthide = selfie.genericDonthide;
|
||||||
this.frozen = true;
|
this.frozen = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1101,7 +1057,7 @@ FilterContainer.prototype.retrieveGenericSelectors = function(request) {
|
||||||
var r = {
|
var r = {
|
||||||
hide: [],
|
hide: [],
|
||||||
// https://github.com/gorhill/uBlock/issues/497
|
// https://github.com/gorhill/uBlock/issues/497
|
||||||
donthide: this.lowGenericDonthide
|
donthide: this.genericDonthide
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( request.highGenerics ) {
|
if ( request.highGenerics ) {
|
||||||
|
@ -1111,13 +1067,7 @@ FilterContainer.prototype.retrieveGenericSelectors = function(request) {
|
||||||
hideMedium: this.highMediumGenericHide,
|
hideMedium: this.highMediumGenericHide,
|
||||||
hideMediumCount: this.highMediumGenericHideCount,
|
hideMediumCount: this.highMediumGenericHideCount,
|
||||||
hideHigh: this.highHighGenericHide,
|
hideHigh: this.highHighGenericHide,
|
||||||
hideHighCount: this.highHighGenericHideCount,
|
hideHighCount: this.highHighGenericHideCount
|
||||||
donthideLow: this.highLowGenericDonthide,
|
|
||||||
donthideLowCount: this.highLowGenericDonthideCount,
|
|
||||||
donthideMedium: this.highMediumGenericDonthide,
|
|
||||||
donthideMediumCount: this.highMediumGenericDonthideCount,
|
|
||||||
donthideHigh: this.highHighGenericDonthide,
|
|
||||||
donthideHighCount: this.highHighGenericDonthideCount
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue