|
|
@ -1,7 +1,7 @@
|
|
|
|
/*******************************************************************************
|
|
|
|
/*******************************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
µMatrix - a Chromium browser extension to black/white list requests.
|
|
|
|
uMatrix - a Chromium browser extension to black/white list requests.
|
|
|
|
Copyright (C) 2014-2016 Raymond Hill
|
|
|
|
Copyright (C) 2014-2018 Raymond Hill
|
|
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
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
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
@ -558,46 +558,50 @@ vAPI.tabs.registerListeners();
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
// Update badge
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// rhill 2013-11-09: well this sucks, I can't update icon/badge
|
|
|
|
|
|
|
|
// incrementally, as chromium overwrite the icon at some point without
|
|
|
|
|
|
|
|
// notifying me, and this causes internal cached state to be out of sync.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
µm.updateBadgeAsync = (function() {
|
|
|
|
µm.updateBadgeAsync = (function() {
|
|
|
|
var tabIdToTimer = Object.create(null);
|
|
|
|
let tabIdToTimer = new Map();
|
|
|
|
|
|
|
|
|
|
|
|
var updateBadge = function(tabId) {
|
|
|
|
let updateBadge = function(tabId) {
|
|
|
|
delete tabIdToTimer[tabId];
|
|
|
|
tabIdToTimer.delete(tabId);
|
|
|
|
|
|
|
|
|
|
|
|
var iconId = null;
|
|
|
|
let iconId = 'off';
|
|
|
|
var badgeStr = '';
|
|
|
|
let badgeStr = '';
|
|
|
|
|
|
|
|
|
|
|
|
var pageStore = this.pageStoreFromTabId(tabId);
|
|
|
|
let pageStore = this.pageStoreFromTabId(tabId);
|
|
|
|
if ( pageStore !== null ) {
|
|
|
|
if ( pageStore !== null ) {
|
|
|
|
var total = pageStore.perLoadAllowedRequestCount +
|
|
|
|
let total = pageStore.perLoadAllowedRequestCount +
|
|
|
|
pageStore.perLoadBlockedRequestCount;
|
|
|
|
pageStore.perLoadBlockedRequestCount;
|
|
|
|
if ( total ) {
|
|
|
|
if ( total ) {
|
|
|
|
var squareSize = 19;
|
|
|
|
let squareSize = 19;
|
|
|
|
var greenSize = squareSize * Math.sqrt(pageStore.perLoadAllowedRequestCount / total);
|
|
|
|
let greenSize = squareSize * Math.sqrt(
|
|
|
|
iconId = greenSize < squareSize/2 ? Math.ceil(greenSize) : Math.floor(greenSize);
|
|
|
|
pageStore.perLoadAllowedRequestCount / total
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
iconId = greenSize < squareSize/2 ?
|
|
|
|
|
|
|
|
Math.ceil(greenSize) :
|
|
|
|
|
|
|
|
Math.floor(greenSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( this.userSettings.iconBadgeEnabled && pageStore.distinctRequestCount !== 0) {
|
|
|
|
if (
|
|
|
|
badgeStr = this.formatCount(pageStore.distinctRequestCount);
|
|
|
|
this.userSettings.iconBadgeEnabled &&
|
|
|
|
|
|
|
|
pageStore.perLoadBlockedRequestCount !== 0
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
badgeStr = this.formatCount(pageStore.perLoadBlockedRequestCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vAPI.setIcon(tabId, iconId, badgeStr);
|
|
|
|
vAPI.setIcon(
|
|
|
|
|
|
|
|
tabId,
|
|
|
|
|
|
|
|
'img/browsericons/icon19-' + iconId + '.png',
|
|
|
|
|
|
|
|
{ text: badgeStr, color: '#666' }
|
|
|
|
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return function(tabId) {
|
|
|
|
return function(tabId) {
|
|
|
|
if ( tabIdToTimer[tabId] ) {
|
|
|
|
if ( tabIdToTimer.has(tabId) ) { return; }
|
|
|
|
return;
|
|
|
|
if ( vAPI.isBehindTheSceneTabId(tabId) ) { return; }
|
|
|
|
}
|
|
|
|
tabIdToTimer.set(
|
|
|
|
if ( vAPI.isBehindTheSceneTabId(tabId) ) {
|
|
|
|
tabId,
|
|
|
|
return;
|
|
|
|
vAPI.setTimeout(updateBadge.bind(this, tabId), 750)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
tabIdToTimer[tabId] = vAPI.setTimeout(updateBadge.bind(this, tabId), 750);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|