1
0
Fork 0
mirror of https://github.com/gorhill/uMatrix.git synced 2024-06-29 03:21:09 +12:00

this fixes #21

This commit is contained in:
gorhill 2014-10-28 00:38:02 -04:00
parent 02e6b2c2d8
commit ff4d827e1f
2 changed files with 14 additions and 13 deletions

View file

@ -71,11 +71,13 @@ var matrixHeaderPrettyNames = {
messaging.start('popup.js'); messaging.start('popup.js');
var onMessage = function(msg) { var onMessage = function(msg) {
if ( msg.what === 'urlStatsChanged' ) { if ( msg.what !== 'urlStatsChanged' ) {
if ( matrixSnapshot.url === msg.pageURL ) { return;
makeMenu();
}
} }
if ( matrixSnapshot.url !== msg.pageURL ) {
return;
}
queryMatrixSnapshot(makeMenu);
}; };
messaging.listen(onMessage); messaging.listen(onMessage);
@ -99,8 +101,7 @@ function setUserSetting(setting, value) {
/******************************************************************************/ /******************************************************************************/
function updateMatrixSnapshot() { function updateMatrixSnapshot() {
var snapshotReady = function(response) { var snapshotReady = function() {
matrixSnapshot = response;
updateMatrixColors(); updateMatrixColors();
updateMatrixBehavior(); updateMatrixBehavior();
updateMatrixButtons(); updateMatrixButtons();
@ -1109,10 +1110,6 @@ function dropDownMenuHide() {
// Because chrome.tabs.query() is async // Because chrome.tabs.query() is async
var onMatrixSnapshotReady = function(response) { var onMatrixSnapshotReady = function(response) {
matrixSnapshot = response;
targetTabId = response.tabId;
// Now that tabId and pageURL are set, we can build our menu // Now that tabId and pageURL are set, we can build our menu
initMenuEnvironment(); initMenuEnvironment();
makeMenu(); makeMenu();
@ -1137,6 +1134,10 @@ var queryMatrixSnapshot = function(callback) {
tabId: targetTabId, tabId: targetTabId,
tabURL: matrixSnapshot.url tabURL: matrixSnapshot.url
}; };
var snapshotReceived = function(response) {
matrixSnapshot = response;
callback();
};
var onTabsReceived = function(tabs) { var onTabsReceived = function(tabs) {
if ( tabs.length === 0 ) { if ( tabs.length === 0 ) {
return; return;
@ -1144,12 +1145,12 @@ var queryMatrixSnapshot = function(callback) {
var tab = tabs[0]; var tab = tabs[0];
request.tabId = targetTabId = tab.id; request.tabId = targetTabId = tab.id;
request.tabURL = tab.url; request.tabURL = tab.url;
messaging.ask(request, callback); messaging.ask(request, snapshotReceived);
}; };
if ( targetTabId === undefined ) { if ( targetTabId === undefined ) {
chrome.tabs.query({ active: true, currentWindow: true }, onTabsReceived); chrome.tabs.query({ active: true, currentWindow: true }, onTabsReceived);
} else { } else {
messaging.ask(request, callback); messaging.ask(request, snapshotReceived);
} }
}; };

View file

@ -422,7 +422,7 @@
'gcPageStats', 'gcPageStats',
null, null,
gcPageStats, gcPageStats,
5 * 60 * 1000, (2.5 * 60 * 1000) | 0,
true true
); );
})(); })();