diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index d0059477a..de201162c 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -65,7 +65,7 @@ vAPI.tabs = {}; /******************************************************************************/ -vAPI.isNoTabId = function(tabId) { +vAPI.isBehindTheSceneTabId = function(tabId) { return tabId.toString() === '-1'; }; diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 58f3d4cc1..ee83d99ba 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -333,7 +333,7 @@ var tabWatcher = { /******************************************************************************/ -vAPI.isNoTabId = function(tabId) { +vAPI.isBehindTheSceneTabId = function(tabId) { return tabId.toString() === '-1'; }; diff --git a/platform/safari/vapi-background.js b/platform/safari/vapi-background.js index eb7af74e1..6f9003393 100644 --- a/platform/safari/vapi-background.js +++ b/platform/safari/vapi-background.js @@ -239,7 +239,7 @@ /******************************************************************************/ - vAPI.isNoTabId = function(tabId) { + vAPI.isBehindTheSceneTabId = function(tabId) { return tabId.toString() === this.noTabId; }; diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index b3b7a1301..6056adba8 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -76,12 +76,16 @@ "description":"English: Go to request log" }, "popupTipNoPopups":{ - "message":"No popups for this site", - "description":"English: No popups for this site" + "message":"Toggle the blocking of all popups for this site", + "description":"English: Toggle the blocking of all popups for this site" }, "popupTipNoStrictBlocking":{ - "message":"No strict blocking for this site", - "description":"English: No strict blocking for this site" + "message":"Toggle strict blocking for this site", + "description":"English: Toggle strict blocking for this site" + }, + "popupTipNoCosmeticFiltering":{ + "message":"Toggle cosmetic filtering for this site", + "description":"English: Toggle cosmetic filtering for this site" }, "popupAnyRulePrompt":{ "message":"all", diff --git a/src/css/popup.css b/src/css/popup.css index ac19119e6..00aff2af6 100644 --- a/src/css/popup.css +++ b/src/css/popup.css @@ -148,7 +148,14 @@ body.off #switch .fa { margin: 0 0.5em; position: relative; } -#extraTools > span.on > span { +#extraTools > span > span.badge { + color: #000; + bottom: -2px; + font: 10px sans-serif; + left: 100%; + position: absolute; + } +#extraTools > span.on > span:last-of-type { color: #e00; font-size: 20px; left: 0; @@ -157,7 +164,7 @@ body.off #switch .fa { top: 0; width: 100%; } -#extraTools > span.on > span:after { +#extraTools > span.on > span:last-of-type:after { content: '\2715'; } @@ -176,7 +183,7 @@ body.advancedUser #panes.dfEnabled h2:before { background-color: #ffe; border: 1px solid #eec; border-radius: 4px; - bottom: 4px; + bottom: 0.7em; color: #888; cursor: pointer; display: none; diff --git a/src/js/async.js b/src/js/async.js index baf3ca49f..0dea156b5 100644 --- a/src/js/async.js +++ b/src/js/async.js @@ -187,7 +187,7 @@ return asyncJobManager; }; var updateBadgeAsync = function(tabId) { - if ( vAPI.isNoTabId(tabId) ) { + if ( vAPI.isBehindTheSceneTabId(tabId) ) { return; } µb.asyncJobs.add('updateBadge-' + tabId, tabId, updateBadge, 250); diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js index dffac98ef..e4650a743 100644 --- a/src/js/contentscript-end.js +++ b/src/js/contentscript-end.js @@ -55,6 +55,7 @@ if ( vAPI.contentscriptEndInjected ) { return; } vAPI.contentscriptEndInjected = true; +vAPI.styles = vAPI.styles || []; /******************************************************************************/ @@ -326,12 +327,12 @@ var uBlockCollapser = (function() { nextRetrieveHandler(response); }; - var nextRetrieveHandler = function(selectors) { + var nextRetrieveHandler = function(response) { //var tStart = timer.now(); //console.debug('µBlock> contextNodes = %o', contextNodes); var hideSelectors = []; - if ( selectors && selectors.hide.length ) { - processLowGenerics(selectors.hide, hideSelectors); + if ( response && response.hide.length ) { + processLowGenerics(response.hide, hideSelectors); } if ( highGenerics ) { if ( highGenerics.hideLowCount ) { @@ -360,14 +361,15 @@ var uBlockCollapser = (function() { var addStyleTag = function(selectors) { var selectorStr = selectors.toString(); - hideElements(selectorStr); var style = document.createElement('style'); // The linefeed before the style block is very important: do no remove! style.appendChild(document.createTextNode(selectorStr + '\n{display:none !important;}')); var parent = document.body || document.documentElement; if ( parent ) { parent.appendChild(style); + vAPI.styles.push(style); } + hideElements(selectorStr); messager.send({ what: 'injectedSelectors', type: 'cosmetic', diff --git a/src/js/contentscript-start.js b/src/js/contentscript-start.js index 7a0bea551..7744d6e7f 100644 --- a/src/js/contentscript-start.js +++ b/src/js/contentscript-start.js @@ -53,6 +53,7 @@ if ( vAPI.contentscriptStartInjected ) { return; } vAPI.contentscriptStartInjected = true; +vAPI.styles = vAPI.styles || []; /******************************************************************************/ @@ -91,7 +92,6 @@ var cosmeticFilters = function(details) { } if ( hide.length !== 0 ) { var text = hide.join(',\n'); - hideElements(text); var style = vAPI.specificHideStyle = document.createElement('style'); // The linefeed before the style block is very important: do not remove! style.appendChild(document.createTextNode(text + '\n{display:none !important;}')); @@ -99,7 +99,9 @@ var cosmeticFilters = function(details) { var parent = document.head || document.documentElement; if ( parent ) { parent.appendChild(style); + vAPI.styles.push(style); } + hideElements(text); } vAPI.donthideCosmeticFilters = donthideCosmeticFilters; vAPI.hideCosmeticFilters = hideCosmeticFilters; diff --git a/src/js/cosmetic-count.js b/src/js/cosmetic-count.js new file mode 100644 index 000000000..bdf51b559 --- /dev/null +++ b/src/js/cosmetic-count.js @@ -0,0 +1,82 @@ +/******************************************************************************* + + uBlock - a browser extension to block requests. + Copyright (C) 2015 Raymond Hill + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see {http://www.gnu.org/licenses/}. + + Home: https://github.com/gorhill/uBlock +*/ + +/* global vAPI, HTMLDocument */ + +/******************************************************************************/ + +(function() { + +'use strict'; + +/******************************************************************************/ + +// https://github.com/gorhill/uBlock/issues/464 +if ( document instanceof HTMLDocument === false ) { + //console.debug('cosmetic-on.js > not a HTLMDocument'); + return; +} + +// Because in case +if ( !vAPI ) { + //console.debug('cosmetic-on.js > vAPI not found'); + return; +} + +/******************************************************************************/ + +// Insert all cosmetic filtering-related style tags in the DOM + +var selectors = []; +var reProperties = /\s*\{[^}]+\}\s*/; +var i; + +var styles = vAPI.styles || []; +i = styles.length; +while ( i-- ) { + selectors.push(styles[i].textContent.replace(reProperties, '')); +} + +var elems = []; + +if ( selectors.length !== 0 ) { + try { + elems = document.querySelectorAll(selectors.join(',')); + } catch (e) { + } +} + +/******************************************************************************/ + +var localMessager = vAPI.messaging.channel('cosmetic-*.js'); + +localMessager.send({ + what: 'hiddenElementCount', + count: elems.length +}, function() { + localMessager.close(); +}); + +/******************************************************************************/ + +})(); + +/******************************************************************************/ diff --git a/src/js/cosmetic-off.js b/src/js/cosmetic-off.js new file mode 100644 index 000000000..7ca962fe0 --- /dev/null +++ b/src/js/cosmetic-off.js @@ -0,0 +1,94 @@ +/******************************************************************************* + + uBlock - a browser extension to block requests. + Copyright (C) 2015 Raymond Hill + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see {http://www.gnu.org/licenses/}. + + Home: https://github.com/gorhill/uBlock +*/ + +/* global vAPI, HTMLDocument */ + +/******************************************************************************/ + +(function() { + +'use strict'; + +/******************************************************************************/ + +// https://github.com/gorhill/uBlock/issues/464 +if ( document instanceof HTMLDocument === false ) { + //console.debug('cosmetic-off.js > not a HTLMDocument'); + return; +} + +// Because in case +if ( !vAPI ) { + //console.debug('cosmetic-off.js > vAPI not found'); + return; +} + +/******************************************************************************/ + +var styles = vAPI.styles; + +if ( Array.isArray(styles) === false ) { + return; +} + +/******************************************************************************/ + +// Remove all cosmetic filtering-related styles from the DOM + +var selectors = []; +var reProperties = /\s*\{[^}]+\}\s*/; +var style, i; + +i = styles.length; +while ( i-- ) { + style = styles[i]; + if ( style.parentElement === null ) { + continue; + } + style.parentElement.removeChild(style); + selectors.push(style.textContent.replace(reProperties, '')); +} + +// Remove `display: none !important` attribute + +if ( selectors.length === 0 ) { + return; +} + +var elems = []; +try { + elems = document.querySelectorAll(selectors.join(',')); +} catch (e) { +} + +i = elems.length; +while ( i-- ) { + style = elems[i].style; + if ( typeof style === 'object' || typeof style.removeProperty === 'function' ) { + style.removeProperty('display'); + } +} + +/******************************************************************************/ + +})(); + +/******************************************************************************/ diff --git a/src/js/cosmetic-on.js b/src/js/cosmetic-on.js new file mode 100644 index 000000000..8cb80dccf --- /dev/null +++ b/src/js/cosmetic-on.js @@ -0,0 +1,98 @@ +/******************************************************************************* + + uBlock - a browser extension to block requests. + Copyright (C) 2015 Raymond Hill + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see {http://www.gnu.org/licenses/}. + + Home: https://github.com/gorhill/uBlock +*/ + +/* global vAPI, HTMLDocument */ + +/******************************************************************************/ + +(function() { + +'use strict'; + +/******************************************************************************/ + +// https://github.com/gorhill/uBlock/issues/464 +if ( document instanceof HTMLDocument === false ) { + //console.debug('cosmetic-on.js > not a HTLMDocument'); + return; +} + +// Because in case +if ( !vAPI ) { + //console.debug('cosmetic-on.js > vAPI not found'); + return; +} + +/******************************************************************************/ + +var styles = vAPI.styles; + +if ( Array.isArray(styles) === false ) { + return; +} + +/******************************************************************************/ + +// Insert all cosmetic filtering-related style tags in the DOM + +var selectors = []; +var reProperties = /\s*\{[^}]+\}\s*/; +var style, i; +var parent = document.head || document.body || document.documentElement; + +i = styles.length; +while ( i-- ) { + style = styles[i]; + if ( style.parentElement !== null ) { + continue; + } + if ( parent === null ) { + continue; + } + selectors.push(style.textContent.replace(reProperties, '')); + parent.appendChild(style); +} + +// Add `display: none !important` attribute + +if ( selectors.length === 0 ) { + return; +} + +var elems = []; +try { + elems = document.querySelectorAll(selectors.join(',')); +} catch (e) { +} + +i = elems.length; +while ( i-- ) { + style = elems[i].style; + if ( typeof style === 'object' || typeof style.removeProperty === 'function' ) { + style.setProperty('display', 'none', 'important'); + } +} + +/******************************************************************************/ + +})(); + +/******************************************************************************/ diff --git a/src/js/document-blocked.js b/src/js/document-blocked.js index f1b6afd7d..248f98394 100644 --- a/src/js/document-blocked.js +++ b/src/js/document-blocked.js @@ -60,7 +60,7 @@ var proceedTemporary = function() { var proceedPermanent = function() { messager.send({ what: 'toggleHostnameSwitch', - name: 'dontBlockDoc', + name: 'noStrictBlocking', hostname: details.hn, state: true }, proceedToURL); diff --git a/src/js/hnswitches.js b/src/js/hnswitches.js index b90e9a04f..27a82bc59 100644 --- a/src/js/hnswitches.js +++ b/src/js/hnswitches.js @@ -37,8 +37,14 @@ var HnSwitches = function() { /******************************************************************************/ var switchBitOffsets = { - 'dontBlockDoc': 0, - 'doBlockAllPopups': 2 + 'noStrictBlocking': 0, + 'noPopups': 2, + 'noCosmeticFiltering': 4 +}; + +var fromLegacySwitchNames = { + 'dontBlockDoc': 'noStrictBlocking', + 'doBlockAllPopups': 'noPopups' }; var switchStateToNameMap = { @@ -253,6 +259,7 @@ HnSwitches.prototype.fromString = function(text) { continue; } switchName = switchName.slice(0, pos); + switchName = fromLegacySwitchNames[switchName] || switchName; if ( switchBitOffsets.hasOwnProperty(switchName) === false ) { continue; } diff --git a/src/js/messaging.js b/src/js/messaging.js index 98fd3534c..c798bacd3 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -76,7 +76,7 @@ var onMessage = function(request, sender, callback) { break; case 'reloadTab': - if ( vAPI.isNoTabId(request.tabId) === false ) { + if ( vAPI.isBehindTheSceneTabId(request.tabId) === false ) { vAPI.tabs.reload(request.tabId); if ( request.select && vAPI.tabs.select ) { vAPI.tabs.select(request.tabId); @@ -233,8 +233,9 @@ var getStats = function(tabId, tabTitle) { r.firewallRules = getFirewallRules(pageStore.pageHostname, r.hostnameDict); r.canElementPicker = r.pageHostname.indexOf('.') !== -1; r.canRequestLog = canRequestLog; - r.doBlockAllPopups = µb.hnSwitches.evaluateZ('doBlockAllPopups', r.pageHostname); - r.dontBlockDoc = µb.hnSwitches.evaluateZ('dontBlockDoc', r.pageHostname); + r.noPopups = µb.hnSwitches.evaluateZ('noPopups', r.pageHostname); + r.noStrictBlocking = µb.hnSwitches.evaluateZ('noStrictBlocking', r.pageHostname); + r.noCosmeticFiltering = µb.hnSwitches.evaluateZ('noCosmeticFiltering', r.pageHostname); } else { r.hostnameDict = {}; r.firewallRules = getFirewallRules(); @@ -284,9 +285,32 @@ var getTargetTabId = function(tab) { /******************************************************************************/ +var getPopupDataLazy = function(tabId, callback) { + var r = { + hiddenElementCount: '' + }; + var pageStore = µb.pageStoreFromTabId(tabId); + + if ( !pageStore ) { + callback(r); + return; + } + + µb.getHiddenElementCount(tabId, function() { + r.hiddenElementCount = pageStore.hiddenElementCount; + callback(r); + }); +}; + +/******************************************************************************/ + var onMessage = function(request, sender, callback) { // Async switch ( request.what ) { + case 'getPopupDataLazy': + getPopupDataLazy(request.tabId, callback); + return; + case 'getPopupData': if ( request.tabId === vAPI.noTabId ) { callback(getStats(vAPI.noTabId, '')); @@ -522,6 +546,56 @@ vAPI.messaging.listen('contentscript-end.js', onMessage); /******************************************************************************/ /******************************************************************************/ +// cosmetic-*.js + +(function() { + +'use strict'; + +/******************************************************************************/ + +var µb = µBlock; + +/******************************************************************************/ + +var onMessage = function(request, sender, callback) { + // Async + switch ( request.what ) { + default: + break; + } + + // Sync + var response; + + var pageStore; + if ( sender && sender.tab ) { + pageStore = µb.pageStoreFromTabId(sender.tab.id); + } + + switch ( request.what ) { + case 'hiddenElementCount': + if ( pageStore ) { + pageStore.hiddenElementCount = request.count; + } + break; + + default: + return vAPI.messaging.UNHANDLED; + } + + callback(response); +}; + +vAPI.messaging.listen('cosmetic-*.js', onMessage); + +/******************************************************************************/ + +})(); + +/******************************************************************************/ +/******************************************************************************/ + // element-picker.js (function() { diff --git a/src/js/pagestore.js b/src/js/pagestore.js index d5d1e4418..f0e3d02f0 100644 --- a/src/js/pagestore.js +++ b/src/js/pagestore.js @@ -488,6 +488,7 @@ PageStore.prototype.init = function(tabId, rawURL, pageURL) { this.netFilteringReadTime = 0; this.perLoadBlockedRequestCount = 0; this.perLoadAllowedRequestCount = 0; + this.hiddenElementCount = ''; // Empty string means "unknown" this.skipLocalMirroring = false; this.netFilteringCache = NetFilteringResultCache.factory(); @@ -614,8 +615,9 @@ PageStore.prototype.getNetFilteringSwitch = function() { PageStore.prototype.getSpecificCosmeticFilteringSwitch = function() { return this.getNetFilteringSwitch() && - (µb.userSettings.advancedUserEnabled && - µb.sessionFirewall.mustAllowCellZY(this.rootHostname, this.rootHostname, '*')) === false; + µb.hnSwitches.evaluateZ('noCosmeticFiltering', this.rootHostname) !== true && + (µb.userSettings.advancedUserEnabled && + µb.sessionFirewall.mustAllowCellZY(this.rootHostname, this.rootHostname, '*')) === false; }; /******************************************************************************/ @@ -623,8 +625,9 @@ PageStore.prototype.getSpecificCosmeticFilteringSwitch = function() { PageStore.prototype.getGenericCosmeticFilteringSwitch = function() { return this.getNetFilteringSwitch() && this.skipCosmeticFiltering === false && - (µb.userSettings.advancedUserEnabled && - µb.sessionFirewall.mustAllowCellZY(this.rootHostname, this.rootHostname, '*')) === false; + µb.hnSwitches.evaluateZ('noCosmeticFiltering', this.rootHostname) !== true && + (µb.userSettings.advancedUserEnabled && + µb.sessionFirewall.mustAllowCellZY(this.rootHostname, this.rootHostname, '*')) === false; }; /******************************************************************************/ diff --git a/src/js/popup.js b/src/js/popup.js index 9317f38f5..386205db4 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -143,9 +143,11 @@ var hashFromPopupData = function(reset) { hasher.push(rule); } } + hasher.sort(); hasher.push(uDom('body').hasClass('off')); + hasher.push(uDom('#noCosmeticFiltering').hasClass('on')); - var hash = hasher.sort().join(''); + var hash = hasher.join(''); if ( reset ) { cachedPopupHash = hash; } @@ -430,8 +432,9 @@ var renderPopup = function() { renderPrivacyExposure(); // Extra tools - uDom('#doBlockAllPopups').toggleClass('on', popupData.doBlockAllPopups === true); - uDom('#dontBlockDoc').toggleClass('on', popupData.dontBlockDoc === true); + uDom('#noPopups').toggleClass('on', popupData.noPopups === true); + uDom('#noStrictBlocking').toggleClass('on', popupData.noStrictBlocking === true); + uDom('#noCosmeticFiltering').toggleClass('on', popupData.noCosmeticFiltering === true); // https://github.com/gorhill/uBlock/issues/470 // This must be done here, to be sure the popup is resized properly @@ -457,6 +460,19 @@ var renderPopup = function() { /******************************************************************************/ +var renderPopupLazy = function() { + var onDataReady = function(data) { + uDom('#noCosmeticFiltering > span.badge').text(data.hiddenElementCount); + }; + + messager.send({ + what: 'getPopupDataLazy', + tabId: popupData.tabId + }, onDataReady); +}; + +/******************************************************************************/ + var toggleNetFilteringSwitch = function(ev) { if ( !popupData || !popupData.pageURL ) { return; @@ -666,8 +682,10 @@ var toggleHostnameSwitch = function() { what: 'toggleHostnameSwitch', name: switchName, hostname: popupData.pageHostname, - state: elem.hasClass('on') + state: elem.hasClass('on'), + tabId: popupData.tabId }); + hashFromPopupData(); }; /******************************************************************************/ @@ -729,6 +747,7 @@ var getPopupData = function(tabId) { var onDataReceived = function(response) { cachePopupData(response); renderPopup(); + renderPopupLazy(); // low priority rendering hashFromPopupData(true); pollForContentChange(); }; diff --git a/src/js/tab.js b/src/js/tab.js index b62c7b048..5c672608b 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -127,8 +127,8 @@ vAPI.tabs.onPopup = function(details) { var result = ''; // Check user switch first - if ( µb.hnSwitches.evaluateZ('doBlockAllPopups', openerHostname) ) { - result = 'ub:doBlockAllPopups true'; + if ( µb.hnSwitches.evaluateZ('noPopups', openerHostname) ) { + result = 'ub:noPopups true'; } // https://github.com/gorhill/uBlock/issues/323 @@ -177,7 +177,7 @@ vAPI.tabs.registerListeners(); // rules which will apply only to that scheme. µb.normalizePageURL = function(tabId, pageURL) { - if ( vAPI.isNoTabId(tabId) ) { + if ( vAPI.isBehindTheSceneTabId(tabId) ) { return 'http://behind-the-scene/'; } var uri = this.URI.set(pageURL); @@ -200,7 +200,9 @@ vAPI.tabs.registerListeners(); // Create an entry for the tab if it doesn't exist. µb.bindTabToPageStats = function(tabId, pageURL, context) { - this.updateBadgeAsync(tabId); + if ( vAPI.isBehindTheSceneTabId(tabId) === false ) { + this.updateBadgeAsync(tabId); + } // https://github.com/gorhill/httpswitchboard/issues/303 // Normalize page URL @@ -220,6 +222,12 @@ vAPI.tabs.registerListeners(); return this.pageStores[tabId] = this.PageStore.factory(tabId, pageURL, normalURL); } + // https://github.com/chrisaljoudi/uBlock/issues/1176 + // Never rebind behind-the-scene scope + if ( vAPI.isBehindTheSceneTabId(tabId) ) { + return pageStore; + } + // https://github.com/gorhill/uBlock/issues/516 // If context if 'beforeRequest', do not rebind if ( context === 'beforeRequest' ) { @@ -300,7 +308,7 @@ var pageStoreJanitor = function() { for ( var i = pageStoreJanitorSampleAt; i < n; i++ ) { tabId = tabIds[i]; // Do not remove behind-the-scene page store - if ( vAPI.isNoTabId(tabId) ) { + if ( vAPI.isBehindTheSceneTabId(tabId) ) { continue; } checkTab(tabId); diff --git a/src/js/traffic.js b/src/js/traffic.js index 6fe0bcb95..7e6929c2a 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -62,7 +62,7 @@ var onBeforeRequest = function(details) { // Special treatment: behind-the-scene requests var tabId = details.tabId; - if ( vAPI.isNoTabId(tabId) ) { + if ( vAPI.isBehindTheSceneTabId(tabId) ) { return onBeforeBehindTheSceneRequest(details); } @@ -201,8 +201,8 @@ var onBeforeRootFrameRequest = function(details) { var result = ''; // Permanently unrestricted? - if ( result === '' && µb.hnSwitches.evaluateZ('dontBlockDoc', requestHostname) ) { - result = 'ua:dontBlockDoc true'; + if ( result === '' && µb.hnSwitches.evaluateZ('noStrictBlocking', requestHostname) ) { + result = 'ua:noStrictBlocking true'; } // Temporarily whitelisted? @@ -351,7 +351,7 @@ var onBeforeBehindTheSceneRequest = function(details) { var onHeadersReceived = function(details) { // Do not interfere with behind-the-scene requests. var tabId = details.tabId; - if ( vAPI.isNoTabId(tabId) ) { + if ( vAPI.isBehindTheSceneTabId(tabId) ) { return; } diff --git a/src/js/ublock.js b/src/js/ublock.js index 95d2f3b9f..c379d01b6 100644 --- a/src/js/ublock.js +++ b/src/js/ublock.js @@ -322,6 +322,25 @@ var matchWhitelistDirective = function(url, hostname, directive) { if ( this.hnSwitches.toggleZ(details.name, details.hostname, details.state) ) { this.saveHostnameSwitches(); } + + // Take action if needed + if ( details.name === 'noCosmeticFiltering' ) { + vAPI.tabs.injectScript(details.tabId, { + file: 'js/cosmetic-' + (details.state ? 'off' : 'on') + '.js', + allFrames: true + }); + return; + } + + // Whatever else + // ... +}; + +/******************************************************************************/ + +µBlock.getHiddenElementCount = function(tabId, callback) { + callback = callback || this.noopFunc; + vAPI.tabs.injectScript(tabId, { file: 'js/cosmetic-count.js' }, callback); }; /******************************************************************************/ diff --git a/src/popup.html b/src/popup.html index 8dfb836af..d75936bb9 100644 --- a/src/popup.html +++ b/src/popup.html @@ -27,8 +27,9 @@

 

 

- - + + +