Update page action icon based on state

This commit is contained in:
Said Achmiz 2019-01-31 15:53:55 -05:00
parent 054b06a4cf
commit 30476e0589
15 changed files with 29 additions and 11 deletions

View File

@ -7,4 +7,22 @@ chrome.runtime.onInstalled.addListener(() => {
], actions: [ new chrome.declarativeContent.ShowPageAction() ] ], actions: [ new chrome.declarativeContent.ShowPageAction() ]
}]); }]);
}); });
});
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
let icons = request.killingStickies ? {
"16": "images/ASK_on_16.png",
"32": "images/ASK_on_32.png",
"48": "images/ASK_on_48.png",
"128": "images/ASK_on_128.png"
} : {
"16": "images/ASK_off_16.png",
"32": "images/ASK_off_32.png",
"48": "images/ASK_off_48.png",
"128": "images/ASK_off_128.png"
};
chrome.pageAction.setIcon({
path: icons,
tabId: sender.tab.id
});
}); });

View File

@ -33,8 +33,8 @@ function checkForShouldKillSticky(result) {
return shouldKillSticky; return shouldKillSticky;
} }
function updateIcon(result) { function updateIcon(shouldKillSticky) {
// TODO: code! chrome.runtime.sendMessage({ "killingStickies" : shouldKillSticky });
} }
/******************/ /******************/
@ -45,7 +45,7 @@ function initialize() {
chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ], chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ],
(result) => { (result) => {
let shouldKillSticky = checkForShouldKillSticky(result); let shouldKillSticky = checkForShouldKillSticky(result);
updateIcon(result); updateIcon(shouldKillSticky);
window.onload = () => { window.onload = () => {
if (shouldKillSticky) killSticky(); if (shouldKillSticky) killSticky();
}; };

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

BIN
images/ASK_off_128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
images/ASK_off_16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
images/ASK_off_32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
images/ASK_off_48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
images/ASK_on_128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
images/ASK_on_16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
images/ASK_on_32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
images/ASK_on_48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -20,17 +20,17 @@
"default_popup": "popup.html", "default_popup": "popup.html",
"default_title": "AlwaysKillSticky - Click the icon to control sticky-killing on this site!", "default_title": "AlwaysKillSticky - Click the icon to control sticky-killing on this site!",
"default_icon": { "default_icon": {
"16": "images/ASK16.png", "16": "images/ASK_on_16.png",
"32": "images/ASK32.png", "32": "images/ASK_on_32.png",
"48": "images/ASK48.png", "48": "images/ASK_on_48.png",
"128": "images/ASK128.png" "128": "images/ASK_on_128.png"
} }
}, },
"icons": { "icons": {
"16": "images/ASK16.png", "16": "images/ASK_on_16.png",
"32": "images/ASK32.png", "32": "images/ASK_on_32.png",
"48": "images/ASK48.png", "48": "images/ASK_on_48.png",
"128": "images/ASK128.png" "128": "images/ASK_on_128.png"
}, },
"options_page": "options.html" "options_page": "options.html"
} }