From 5213fecaad215f45ec37b2d7c2a075d6de85be45 Mon Sep 17 00:00:00 2001 From: gorhill Date: Mon, 23 Jun 2014 19:23:36 -0400 Subject: [PATCH] fixed turning off cosmetic filters --- js/abp-hide-filters.js | 14 ++++++++++---- js/background.js | 2 +- js/messaging-handlers.js | 10 ++++++++-- js/ublock.js | 34 ++++++++++++++++++++++++++-------- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/js/abp-hide-filters.js b/js/abp-hide-filters.js index 3f4bfdde5..d036af1e8 100644 --- a/js/abp-hide-filters.js +++ b/js/abp-hide-filters.js @@ -554,11 +554,13 @@ FilterContainer.prototype.addFilterEntry = function(hash, f) { /******************************************************************************/ -FilterContainer.prototype.retrieveGenericSelectors = function(request) { +FilterContainer.prototype.retrieveGenericSelectors = function(tabHostname, request) { + if ( !tabHostname || µb.getCosmeticFilteringSwitch(tabHostname) !== true ) { + return; + } if ( µb.userSettings.parseAllABPHideFilters !== true ) { return; } - if ( !request.selectors ) { return; } @@ -614,11 +616,13 @@ FilterContainer.prototype.retrieveGenericSelectors = function(request) { /******************************************************************************/ -FilterContainer.prototype.retrieveDomainSelectors = function(request) { +FilterContainer.prototype.retrieveDomainSelectors = function(tabHostname, request) { + if ( !tabHostname || µb.getCosmeticFilteringSwitch(tabHostname) !== true ) { + return; + } if ( µb.userSettings.parseAllABPHideFilters !== true ) { return; } - if ( !request.locationURL ) { return; } @@ -629,11 +633,13 @@ FilterContainer.prototype.retrieveDomainSelectors = function(request) { //bucketTestCount = 0; var hostname = pageHostname = µb.URI.hostnameFromURI(request.locationURL); + var r = { domain: µb.URI.domainFromHostname(hostname), hide: [], donthide: [] }; + var bucket; var hash = makePrefixHash('#', r.domain); if ( bucket = this.filters[hash] ) { diff --git a/js/background.js b/js/background.js index b9b602364..cd414bc78 100644 --- a/js/background.js +++ b/js/background.js @@ -33,7 +33,7 @@ return { userSettings: { showIconBadge: true, parseAllABPHideFilters: true, - exceptionList: {} + netExceptionList: {} }, localSettings: { blockedRequestCount: 0, diff --git a/js/messaging-handlers.js b/js/messaging-handlers.js index 30c39b33d..25befaf86 100644 --- a/js/messaging-handlers.js +++ b/js/messaging-handlers.js @@ -104,13 +104,19 @@ var onMessage = function(request, sender, callback) { // Sync var response; + var pageStore; + if ( sender && sender.tab ) { + pageStore = µBlock.pageStoreFromTabId(sender.tab.id); + } + var tabHostname = pageStore ? pageStore.pageHostname : ''; + switch ( request.what ) { case 'retrieveDomainCosmeticSelectors': - response = µBlock.abpHideFilters.retrieveDomainSelectors(request); + response = µBlock.abpHideFilters.retrieveDomainSelectors(tabHostname, request); break; case 'retrieveGenericCosmeticSelectors': - response = µBlock.abpHideFilters.retrieveGenericSelectors(request); + response = µBlock.abpHideFilters.retrieveGenericSelectors(tabHostname, request); break; default: diff --git a/js/ublock.js b/js/ublock.js index a9ee20178..95fe994b0 100644 --- a/js/ublock.js +++ b/js/ublock.js @@ -24,13 +24,13 @@ /******************************************************************************/ µBlock.getNetFilteringSwitch = function(hostname) { - var exceptionList = this.userSettings.exceptionList; - if ( exceptionList[hostname] !== undefined ) { + var netExceptionList = this.userSettings.netExceptionList; + if ( netExceptionList[hostname] !== undefined ) { return false; } var hostnames = this.URI.parentHostnamesFromHostname(hostname); while ( hostname = hostnames.shift() ) { - if ( exceptionList[hostname] !== undefined ) { + if ( netExceptionList[hostname] !== undefined ) { return false; } } @@ -47,11 +47,11 @@ if ( newState === currentState ) { return currentState; } - var exceptionList = this.userSettings.exceptionList; + var netExceptionList = this.userSettings.netExceptionList; // Add to exception list if ( !newState ) { - exceptionList[hostname] = true; + netExceptionList[hostname] = true; this.saveExceptionList(); return true; } @@ -60,8 +60,8 @@ if ( newState ) { var hostnames = this.URI.allHostnamesFromHostname(hostname); while ( hostname = hostnames.shift() ) { - if ( exceptionList[hostname] !== undefined ) { - delete exceptionList[hostname]; + if ( netExceptionList[hostname] !== undefined ) { + delete netExceptionList[hostname]; } } this.saveExceptionList(); @@ -71,9 +71,27 @@ /******************************************************************************/ +// For now we will use the net exception list + +µBlock.getCosmeticFilteringSwitch = function(hostname) { + var netExceptionList = this.userSettings.netExceptionList; + if ( netExceptionList[hostname] !== undefined ) { + return false; + } + var hostnames = this.URI.parentHostnamesFromHostname(hostname); + while ( hostname = hostnames.shift() ) { + if ( netExceptionList[hostname] !== undefined ) { + return false; + } + } + return true; +}; + +/******************************************************************************/ + µBlock.saveExceptionList = function() { chrome.storage.local.set({ - 'exceptionList': this.userSettings.exceptionList + 'netExceptionList': this.userSettings.netExceptionList }); };