support elemhide filter option

This commit is contained in:
gorhill 2015-01-08 21:04:48 -05:00
parent 5bc2309357
commit ba31014503
3 changed files with 20 additions and 1 deletions

View File

@ -402,7 +402,7 @@ var onMessage = function(details, sender, callback) {
switch ( details.what ) {
case 'retrieveGenericCosmeticSelectors':
if ( pageStore && pageStore.getNetFilteringSwitch() ) {
if ( pageStore && pageStore.getCosmeticFilteringSwitch() ) {
response = µb.cosmeticFilteringEngine.retrieveGenericSelectors(details);
}
break;

View File

@ -492,6 +492,12 @@ PageStore.prototype.init = function(tabId, pageURL) {
this.skipLocalMirroring = false;
this.netFilteringCache = NetFilteringResultCache.factory();
// Support `elemhide` filter option. Called at this point so the required
// context is all setup at this point.
this.skipCosmeticFiltering = µb.staticNetFilteringEngine
.matchStringExactType(this, pageURL, 'cosmetic-filtering')
.charAt(1) === 'b';
// Preserve old buffer if there is one already, it may be in use, and
// overwritting it would required another read to restart it.
if ( this.logBuffer instanceof LogBuffer === false ) {
@ -596,6 +602,13 @@ PageStore.prototype.getNetFilteringSwitch = function() {
/******************************************************************************/
PageStore.prototype.getCosmeticFilteringSwitch = function() {
return this.getNetFilteringSwitch() === false ||
this.skipCosmeticFiltering == false;
};
/******************************************************************************/
PageStore.prototype.filterRequest = function(context) {
if ( this.getNetFilteringSwitch() === false ) {
this.cacheResult(context, '');

View File

@ -64,6 +64,7 @@ var typeNameToTypeValue = {
'xmlhttprequest': 6 << 4,
'sub_frame': 7 << 4,
'other': 8 << 4,
'cosmetic-filtering': 13 << 4,
'inline-script': 14 << 4,
'popup': 15 << 4
};
@ -1245,6 +1246,11 @@ FilterParser.prototype.parse = function(s) {
this.parseOptParty(not);
continue;
}
if ( opt === 'elemhide' && this.action === AllowAction ) {
this.types.push(typeNameToTypeValue['cosmetic-filtering']);
this.action = BlockAction;
continue;
}
if ( this.toNormalizedType.hasOwnProperty(opt) ) {
this.parseOptType(opt, not);
continue;