Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom Selection Tools in the right-click context menu #778

Open
PeterDaveHello opened this issue Aug 16, 2024 · 1 comment

Comments

@PeterDaveHello
Copy link
Contributor

Is your feature request related to a problem? Please describe.
On some websites, the floating toolbar with Selection Tools may not appear due to compatibility issues(maybe?). This limits the ability to use custom actions that have been set up.

Describe the solution you'd like
It would be beneficial if the custom Selection Tools options (like enabling/disabling features and adding new ones) were also available in the right-click context menu, which generally works consistently across sites.

Additional context
Adding these customization options to the right-click menu would provide a more reliable and accessible way to use the tools, especially on sites where the floating toolbar doesn't function properly.

@creesch
Copy link

creesch commented Sep 5, 2024

I was trialing the extension and this is also something I noticed. For me the issue is that I rather not have something popup every time I select something. So I'd like to exclusively use the context menu.

I am hoping to have some time to look into the code base myself. However if someone else wants to tackle this, it is quite easy to dynamically change the menu. Below is an example I grabbed from an extension I have developed myself. Where the function initializeContextMenu is part of the background worker and updates the menu whenever settigns change.

function initializeContextMenu () {
    // Clear existing context menu items
    chrome.contextMenus.removeAll(async () => {
        // Add new context menu items based on current settings
        chrome.contextMenus.create({
            id: 'mainEntry',
            title: 'Main entry',
            contexts: ['selection'],
        });

        // Get the setting that will contain the various menu items. The `getSetting` function here is just a wrapper around `chrome.storage.local` which will return a default setting if it is null. 
        const menuItems = await getSetting('menuItems');
        // Add the individual menu items. 
        menuItems.forEach((item, index) => {
            chrome.contextMenus.create({
                id: index.toString(),
                parentId: 'mainEntry',
                title: item.title,
                contexts: ['selection'],
            });
        });
    });
}

// Run when installed and on startup. 
chrome.runtime.onInstalled.addListener(initializeContextMenu);
chrome.runtime.onStartup.addListener(initializeContextMenu);

// run when settings are changed. 
chrome.storage.onChanged.addListener(changes => {
    if ('menuItems' in changes) {
        initializeContextMenu();
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants