mirror of
https://github.com/gorhill/uMatrix.git
synced 2024-10-01 01:26:16 +13:00
code review
This commit is contained in:
parent
37331b1ef2
commit
f4807b6b29
1 changed files with 20 additions and 8 deletions
|
@ -571,26 +571,38 @@ PageStore.prototype.recordRequest = function(type, url, block) {
|
||||||
// notifying me, and this causes internal cached state to be out of sync.
|
// notifying me, and this causes internal cached state to be out of sync.
|
||||||
|
|
||||||
PageStore.prototype.updateBadgeAsync = (function() {
|
PageStore.prototype.updateBadgeAsync = (function() {
|
||||||
var updateBadge = function() {
|
var tabIdToTimer = {};
|
||||||
this.updateBadgeTimer = null;
|
|
||||||
|
var updateBadge = function(tabId) {
|
||||||
|
delete tabIdToTimer[tabId];
|
||||||
|
|
||||||
|
var pageStore = µm.pageStoreFromTabId(tabId);
|
||||||
|
if ( pageStore === null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var iconId = null;
|
var iconId = null;
|
||||||
var badgeStr = '';
|
var badgeStr = '';
|
||||||
var total = this.perLoadAllowedRequestCount + this.perLoadBlockedRequestCount;
|
var total = pageStore.perLoadAllowedRequestCount +
|
||||||
|
pageStore.perLoadBlockedRequestCount;
|
||||||
if ( total ) {
|
if ( total ) {
|
||||||
var squareSize = 19;
|
var squareSize = 19;
|
||||||
var greenSize = squareSize * Math.sqrt(this.perLoadAllowedRequestCount / total);
|
var greenSize = squareSize * Math.sqrt(pageStore.perLoadAllowedRequestCount / total);
|
||||||
iconId = greenSize < squareSize/2 ? Math.ceil(greenSize) : Math.floor(greenSize);
|
iconId = greenSize < squareSize/2 ? Math.ceil(greenSize) : Math.floor(greenSize);
|
||||||
badgeStr = µm.formatCount(this.distinctRequestCount);
|
badgeStr = µm.formatCount(pageStore.distinctRequestCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
vAPI.setIcon(this.tabId, iconId, badgeStr);
|
vAPI.setIcon(tabId, iconId, badgeStr);
|
||||||
};
|
};
|
||||||
|
|
||||||
return function() {
|
return function() {
|
||||||
if ( this.updateBadgeTimer === null ) {
|
if ( vAPI.isBehindTheSceneTabId(this.tabId) ) {
|
||||||
this.updateBadgeTimer = setTimeout(updateBadge.bind(this), 500);
|
return;
|
||||||
}
|
}
|
||||||
|
if ( tabIdToTimer.hasOwnProperty(this.tabId) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tabIdToTimer[this.tabId] = setTimeout(updateBadge.bind(null, this.tabId), 500);
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue