Skip to content

Loading…

Add a toolbar button context menu checkbox to toggle the number #1097

Open
tophf opened this Issue · 4 comments

2 participants

@tophf

Why?

Because as a user I see a button and I want to customize its appearance so what do I do? I right-click it and immediately see the related checkbox. Easy.

Docs
The manifest should have contextMenus in permissions.
Here's an example:

chrome.contextMenus.create({
    id: "toggleNumber", title: chrome.i18n.getMessage("toggleNumberLabel"),
    type: "checkbox", contexts: ["browser_action"], checked: getPref("toggleNumber")
});
chrome.contextMenus.onClicked.addListener(function(info, tab) {
    if (info.menuItemId == "toggleNumber") {
        setPref(info.menuItemId, info.checked);
        updateToolbarButtonNumber();
    }
});
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
    if (request.method == "prefChanged"  && request.prefName == "toggleNumber") {
        chrome.contextMenus.update("toggleNumber", {checked: request.value});
    }
});

The options page should notify the background page:

chrome.extension.sendMessage({method: "prefChanged", prefName : "toggleNumber", value: newValue});

Actually it'd be reasonable to include the other three global behavior options as well!

@gorhill

Sorry, such a global setting does not have a place in a context menu.

@gorhill gorhill closed this
@tophf

Well, the toolbar button context menu has a much more global stuff like "Remove from Chrome", "Manage extensions" and so on. It's quite evident that your justification was invalid.

@gorhill

global stuff like "Remove from Chrome"

Oh ok, you mean the icon's context menu, I thought you meant the page's context menu.

@gorhill gorhill reopened this
@tophf

And there I thought the screenshot isn't needed, oh boy :-) Now I'll be always providing one, just in case :grinning:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.