This commit is contained in:
gorhill 2016-08-06 12:05:01 -04:00
parent 2b8f960d32
commit 6bd356dd2c
3 changed files with 55 additions and 59 deletions

View File

@ -22,12 +22,12 @@
/******************************************************************************/
/******************************************************************************/
'use strict';
// Default handler
(function() {
'use strict';
/******************************************************************************/
var µb = µBlock;
@ -192,8 +192,6 @@ vAPI.messaging.setup(onMessage);
(function() {
'use strict';
/******************************************************************************/
var µb = µBlock;
@ -356,30 +354,17 @@ var popupDataFromRequest = function(request, callback) {
/******************************************************************************/
var getPopupDataLazy = function(tabId, callback) {
var r = {
hiddenElementCount: ''
};
var pageStore = µb.pageStoreFromTabId(tabId);
if ( !pageStore ) {
callback(r);
return;
}
µb.scriptlets.inject(tabId, 'cosmetic-survey', function() {
r.hiddenElementCount = pageStore.hiddenElementCount;
callback(r);
});
};
/******************************************************************************/
var onMessage = function(request, sender, callback) {
var pageStore;
// Async
switch ( request.what ) {
case 'getPopupDataLazy':
getPopupDataLazy(request.tabId, callback);
case 'getPopupLazyData':
pageStore = µb.pageStoreFromTabId(request.tabId);
if ( pageStore !== null ) {
pageStore.hiddenElementCount = 0;
µb.scriptlets.injectDeep(request.tabId, 'cosmetic-survey');
}
return;
case 'getPopupData':
@ -391,7 +376,6 @@ var onMessage = function(request, sender, callback) {
}
// Sync
var pageStore;
var response;
switch ( request.what ) {
@ -454,8 +438,6 @@ vAPI.messaging.listen('popupPanel', onMessage);
(function() {
'use strict';
/******************************************************************************/
var µb = µBlock;
@ -585,8 +567,6 @@ vAPI.messaging.listen('contentscript', onMessage);
(function() {
'use strict';
/******************************************************************************/
var µb = µBlock;
@ -665,8 +645,6 @@ vAPI.messaging.listen('elementPicker', onMessage);
(function() {
'use strict';
/******************************************************************************/
var µb = µBlock;
@ -727,8 +705,6 @@ vAPI.messaging.listen('cloudWidget', onMessage);
(function() {
'use strict';
/******************************************************************************/
var µb = µBlock;
@ -1031,8 +1007,6 @@ vAPI.messaging.listen('dashboard', onMessage);
(function() {
'use strict';
/******************************************************************************/
var µb = µBlock;
@ -1146,8 +1120,6 @@ vAPI.messaging.listen('loggerUI', onMessage);
(function() {
'use strict';
/******************************************************************************/
var onMessage = function(request, sender, callback) {
@ -1185,11 +1157,27 @@ vAPI.messaging.listen('documentBlocked', onMessage);
(function() {
'use strict';
/******************************************************************************/
var µb = µBlock;
var broadcastTimers = Object.create(null);
/******************************************************************************/
var cosmeticallyFilteredElementCountChanged = function(tabId) {
delete broadcastTimers[tabId + '-cosmeticallyFilteredElementCountChanged'];
var pageStore = µb.pageStoreFromTabId(tabId);
if ( pageStore === null ) {
return;
}
vAPI.messaging.broadcast({
what: 'cosmeticallyFilteredElementCountChanged',
tabId: tabId,
count: pageStore.hiddenElementCount
});
};
/******************************************************************************/
@ -1231,9 +1219,16 @@ var onMessage = function(request, sender, callback) {
var response;
switch ( request.what ) {
case 'liveCosmeticFilteringData':
if ( pageStore !== null ) {
pageStore.hiddenElementCount = request.filteredElementCount;
case 'cosmeticallyFilteredElementCount':
if ( pageStore !== null && request.filteredElementCount ) {
pageStore.hiddenElementCount += request.filteredElementCount;
var broadcastKey = tabId + '-cosmeticallyFilteredElementCountChanged';
if ( broadcastTimers[broadcastKey] === undefined ) {
broadcastTimers[broadcastKey] = vAPI.setTimeout(
cosmeticallyFilteredElementCountChanged.bind(null, tabId),
250
);
}
}
break;

View File

@ -21,12 +21,12 @@
/* global punycode, uDom */
'use strict';
/******************************************************************************/
(function() {
'use strict';
/******************************************************************************/
// Ensure the popup is properly sized as soon as possible. It is assume the DOM
@ -507,23 +507,24 @@ var renderPopup = function() {
/******************************************************************************/
var renderPopupLazy = function() {
var onDataReady = function(data) {
if ( !data ) { return; }
var v = data.hiddenElementCount || '';
messaging.send('popupPanel', { what: 'getPopupLazyData', tabId: popupData.tabId });
};
var onPopupMessage = function(data) {
if ( !data ) { return; }
if ( data.tabId !== popupData.tabId ) { return; }
switch ( data.what ) {
case 'cosmeticallyFilteredElementCountChanged':
var v = data.count || '';
uDom.nodeFromSelector('#no-cosmetic-filtering > span.badge')
.textContent = typeof v === 'number' ? v.toLocaleString() : v;
};
messaging.send(
'popupPanel',
{
what: 'getPopupDataLazy',
tabId: popupData.tabId
},
onDataReady
);
break;
}
};
messaging.addChannelListener('popup', onPopupMessage);
/******************************************************************************/
var toggleNetFilteringSwitch = function(ev) {

View File

@ -39,7 +39,7 @@
vAPI.messaging.send(
'scriptlets',
{
what: 'liveCosmeticFilteringData',
what: 'cosmeticallyFilteredElementCount',
pageURL: window.location.href,
filteredElementCount: xpr && xpr.numberValue || 0
}