DEV Community

Sem
Sem

Posted on • Originally published at semihcelikol.com

Firefox Add-Ons - Search on Twitter

Hi,
I develop Firefox Add-Ons(extension) tool, selected text > right click > search on twitter

Add-Ons Link: https://addons.mozilla.org/tr/firefox/addon/search-onn-twitter/

Github link: https://github.com/semihcelikol/searchOnTwitter

Manifest.json

    {
        "manifest_version": 2,
        "name":"Search on Twitter",
        "description": "Selected text Search on Twitter",
        "version": "1.0",
        "author": "Semih Çelikol",
        "homepage_url": "http://semihcelikol.com",
        "icons": {
            "48": "icons/icon48.png",
            "64": "icons/icon64.png",
            "96": "icons/icon96.png"
        },
        "permissions": ["contextMenus"],
        "background": {
            "scripts": [
                "background.js"
            ]
        }
    }
Enter fullscreen mode Exit fullscreen mode

background.js

    browser.contextMenus.create({
        id: "tts",
        title: "Search on Twitter",
        contexts: ["selection"]
    });

    browser.contextMenus.onClicked.addListener(contextMenuAction);

    function contextMenuAction(info, tab){
        const url = "https://twitter.com/search?q="+ info.selectionText+ "&src=typed_query";

        browser.tabs.create({url:url});
    }
Enter fullscreen mode Exit fullscreen mode

See more: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Context_menu_items

Top comments (0)