pull/2/head
Raymond Hill 7 years ago
parent b963ccb778
commit ebfe08e0a2
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

@ -1,8 +1,8 @@
/******************************************************************************* /*******************************************************************************
uMatrix - a browser extension to block requests. uMatrix - a browser extension to block requests.
Copyright (C) 2014-2017 The uBlock Origin authors Copyright (C) 2014-2018 The uBlock Origin authors
Copyright (C) 2017 Raymond Hill Copyright (C) 2017-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
@ -381,32 +381,32 @@ vAPI.tabs.injectScript = function(tabId, details, callback) {
// Since we may be called asynchronously, the tab id may not exist // Since we may be called asynchronously, the tab id may not exist
// anymore, so this ensures it does still exist. // anymore, so this ensures it does still exist.
vAPI.setIcon = function(tabId, iconId, badge) { vAPI.setIcon = (function() {
tabId = parseInt(tabId, 10); let onIconReady = function(tabId, badgeDetails) {
if ( isNaN(tabId) || tabId <= 0 ) { if ( vAPI.lastError() ) { return; }
return; if ( badgeDetails.text !== undefined ) {
} chrome.browserAction.setBadgeText({
var onIconReady = function() { tabId: tabId,
if ( vAPI.lastError() ) { text: badgeDetails.text
return; });
} }
chrome.browserAction.setBadgeText({ tabId: tabId, text: badge }); if ( badgeDetails.color !== undefined ) {
if ( badge !== '' ) {
chrome.browserAction.setBadgeBackgroundColor({ chrome.browserAction.setBadgeBackgroundColor({
tabId: tabId, tabId: tabId,
color: '#000' color: badgeDetails.color
}); });
} }
}; };
var iconSelector = typeof iconId === 'number' ? iconId : 'off'; return function(tabId, iconDetails, badgeDetails) {
var iconPaths = { tabId = parseInt(tabId, 10);
'19': 'img/browsericons/icon19-' + iconSelector + '.png'/* , if ( isNaN(tabId) || tabId === -1 ) { return; }
'38': 'img/browsericons/icon38-' + iconSelector + '.png' */ chrome.browserAction.setIcon(
{ tabId: tabId, path: iconDetails },
function() { onIconReady(tabId, badgeDetails); }
);
}; };
})();
chrome.browserAction.setIcon({ tabId: tabId, path: iconPaths }, onIconReady);
};
/******************************************************************************/ /******************************************************************************/
/******************************************************************************/ /******************************************************************************/

@ -291,7 +291,7 @@
"description": "" "description": ""
}, },
"settingsIconBadgeEnabled":{ "settingsIconBadgeEnabled":{
"message":"Show the number of distinct requests on the icon", "message":"Show the number of blocked resources on the icon",
"description":"" "description":""
}, },
"settingsMatrixDisplayColorBlind" : { "settingsMatrixDisplayColorBlind" : {

@ -573,7 +573,7 @@ var onMessage = function(request, sender, callback) {
request.documentURI; request.documentURI;
if ( pageStore !== null ) { if ( pageStore !== null ) {
pageStore.hasWebWorkers = true; pageStore.hasWebWorkers = true;
pageStore.recordRequest('script', url, true); pageStore.recordRequest('script', url, request.blocked);
} }
if ( tabContext !== null ) { if ( tabContext !== null ) {
µm.logger.writeOne(tabId, 'net', rootHostname, url, 'worker', request.blocked); µm.logger.writeOne(tabId, 'net', rootHostname, url, 'worker', request.blocked);

@ -1,7 +1,7 @@
/******************************************************************************* /*******************************************************************************
uMatrix - a Chromium browser extension to black/white list requests. uMatrix - a Chromium browser extension to black/white list requests.
Copyright (C) 2013-2017 Raymond Hill Copyright (C) 2013-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
@ -204,6 +204,12 @@ PageStore.prototype = {
}, },
recordRequest: function(type, url, block) { recordRequest: function(type, url, block) {
if ( block ) {
this.perLoadBlockedRequestCount++;
} else {
this.perLoadAllowedRequestCount++;
}
// Store distinct network requests. This is used to: // Store distinct network requests. This is used to:
// - remember which hostname/type were seen // - remember which hostname/type were seen
// - count the number of distinct URLs for any given // - count the number of distinct URLs for any given
@ -228,12 +234,6 @@ PageStore.prototype = {
µm.requestStats.record(type, block); µm.requestStats.record(type, block);
µm.updateBadgeAsync(this.tabId); µm.updateBadgeAsync(this.tabId);
if ( block !== false ) {
this.perLoadBlockedRequestCount++;
} else {
this.perLoadAllowedRequestCount++;
}
this.distinctRequestCount++; this.distinctRequestCount++;
this.mtxCountModifiedTime = Date.now(); this.mtxCountModifiedTime = Date.now();

@ -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);
}; };
})(); })();

@ -47,6 +47,8 @@ var onBeforeRootFrameRequestHandler = function(details) {
var pageStore = µm.pageStoreFromTabId(tabId); var pageStore = µm.pageStoreFromTabId(tabId);
pageStore.recordRequest('doc', requestURL, block); pageStore.recordRequest('doc', requestURL, block);
pageStore.perLoadAllowedRequestCount = 0;
pageStore.perLoadBlockedRequestCount = 0;
µm.logger.writeOne(tabId, 'net', rootHostname, requestURL, 'doc', block); µm.logger.writeOne(tabId, 'net', rootHostname, requestURL, 'doc', block);
// Not blocked // Not blocked

Loading…
Cancel
Save