Skip to content

Commit

Permalink
Merge pull request leggett#117 from ndobryanskyy/page-action-icons-fix
Browse files Browse the repository at this point in the history
leggett#43 - fix icons scaling
  • Loading branch information
leggett authored Apr 29, 2019
2 parents 7849961 + c8ac6d2 commit eec0f91
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
10 changes: 1 addition & 9 deletions gmail/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@
"48": "img/icon48.png",
"128": "img/icon128.png"
},
"page_action": {
"default_icon": {
"16": "img/icon16.png",
"24": "img/icon24.png",
"32": "img/icon32.png",
"48": "img/icon48.png",
"128": "img/icon128.png"
}
},
"page_action": {},
"content_scripts": [{
"matches": ["*://mail.google.com/mail/*"],
"js": ["script.js"],
Expand Down
29 changes: 21 additions & 8 deletions gmail/pageActionHandler.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
const toggleOnTitle = 'Enable Simplify';
const toggleOffTitle = 'Temporarily disable Simplify';

function updateTitle(tabId, toggled) {
const toggledOnIcon = {
16: "img/icon16.png",
24: "img/icon24.png",
32: "img/icon32.png",
48: "img/icon48.png",
128: "img/icon128.png"
}

const toggledOffIcon = {
16: "img/icon16_off.png",
24: "img/icon24_off.png",
32: "img/icon32_off.png",
48: "img/icon48_off.png",
128: "img/icon128_off.png"
}

function updatePageAction(tabId, toggled) {
chrome.pageAction.setTitle({
tabId: tabId,
title: toggled ? toggleOffTitle : toggleOnTitle
});
}

function updateIcon(tabId, toggled) {
chrome.pageAction.setIcon({
tabId: tabId,
path: toggled ? 'img/icon128.png' : 'img/icon128_off.png'
path: toggled ? toggledOnIcon : toggledOffIcon
});
}

chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
if (message.action === 'activate_page_action') {
const tabId = sender.tab.id;

updateTitle(tabId, true);
updatePageAction(tabId, true);
chrome.pageAction.show(tabId);
}
});

chrome.pageAction.onClicked.addListener(function (tab) {
const tabId = tab.id;

chrome.tabs.sendMessage(tabId, {action: 'toggle_simpl'}, function(response) {
updateTitle(tabId, response.toggled);
updateIcon(tabId, response.toggled);
chrome.tabs.sendMessage(tabId, {action: 'toggle_simpl'}, function(response) {
updatePageAction(tabId, response.toggled);
});
});

0 comments on commit eec0f91

Please sign in to comment.