From f141d6f76924594b40dfc7ae3339ebdcfe1d0df2 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 26 Nov 2014 17:26:33 -0200 Subject: [PATCH] fixed overzealous cosmetic filter bug introduced in #365 --- src/js/contentscript-end.js | 16 +++++++++++++--- src/js/contentscript-start.js | 16 +++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js index ae7867bf2..6eeda9f80 100644 --- a/src/js/contentscript-end.js +++ b/src/js/contentscript-end.js @@ -43,7 +43,7 @@ var messager = vAPI.messaging.channel('contentscript-end.js'); (function() { var queriedSelectors = {}; - var injectedSelectors = vAPI.injectedCosmeticFilters || {}; + var injectedSelectors = vAPI.hideCosmeticFilters || {}; var classSelectors = null; var idSelectors = null; var highGenerics = null; @@ -55,9 +55,19 @@ var messager = vAPI.messaging.channel('contentscript-end.js'); // Ensure injected styles are enforced // rhill 2014-11-16: not sure this is needed anymore. Test case in // above issue was fine without the line below.. - if ( vAPI.injectedCosmeticFilters ) { - hideElements(Object.keys(vAPI.injectedCosmeticFilters).join(',')); + if ( vAPI.hideCosmeticFilters ) { + hideElements(Object.keys(vAPI.hideCosmeticFilters).join(',')); } + // Add exception filters into injected filters collection, in order + // to force them to be seen as "already injected". + var donthideCosmeticFilters = vAPI.donthideCosmeticFilters; + for ( var selector in donthideCosmeticFilters ) { + if ( donthideCosmeticFilters.hasOwnProperty(selector) === false ) { + continue; + } + injectedSelectors[selector] = true; + } + // Now scan content of page idsFromNodeList(document.querySelectorAll('[id]')); classesFromNodeList(document.querySelectorAll('[class]')); retrieveGenericSelectors(); diff --git a/src/js/contentscript-start.js b/src/js/contentscript-start.js index 533706df2..aed3f4f53 100644 --- a/src/js/contentscript-start.js +++ b/src/js/contentscript-start.js @@ -22,8 +22,6 @@ /* jshint multistr: true */ /* global vAPI */ -'use strict'; - /******************************************************************************/ // Injected into content pages @@ -32,6 +30,8 @@ (function() { +'use strict'; + /******************************************************************************/ // because Safari @@ -55,7 +55,8 @@ var cosmeticFilters = function(details) { if ( style !== null ) { return; } - var injectedCosmeticFilters = {}; + var donthideCosmeticFilters = {}; + var hideCosmeticFilters = {}; style = document.createElement('style'); style.setAttribute('id', 'ublock-preload-1ae7a5f130fc79b4fdb8a4272d9426b5'); var donthide = details.cosmeticDonthide; @@ -65,7 +66,7 @@ var cosmeticFilters = function(details) { donthide = donthide.split(',\n'); var i = donthide.length; while ( i-- ) { - injectedCosmeticFilters[donthide[i]] = true; + donthideCosmeticFilters[donthide[i]] = true; } // https://github.com/gorhill/uBlock/issues/143 if ( hide.length !== 0 ) { @@ -75,10 +76,10 @@ var cosmeticFilters = function(details) { var selector; while ( i-- ) { selector = hide[i]; - if ( injectedCosmeticFilters[selector] ) { + if ( donthideCosmeticFilters[selector] ) { hide.splice(i, 1); } else { - injectedCosmeticFilters[selector] = true; + hideCosmeticFilters[selector] = true; } } } @@ -94,7 +95,8 @@ var cosmeticFilters = function(details) { if ( parent ) { parent.appendChild(style); } - vAPI.injectedCosmeticFilters = injectedCosmeticFilters; + vAPI.donthideCosmeticFilters = donthideCosmeticFilters; + vAPI.hideCosmeticFilters = hideCosmeticFilters; }; var netFilters = function(details) {