Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
support elemhide filter option
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jan 9, 2015
1 parent 5bc2309 commit ba31014
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions src/js/pagestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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, '');
Expand Down
6 changes: 6 additions & 0 deletions src/js/static-net-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down Expand Up @@ -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;
Expand Down

1 comment on commit ba31014

@gorhill
Copy link
Contributor Author

@gorhill gorhill commented on ba31014 Jan 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related issue: #26

Please sign in to comment.