If you just want to install the addon you can do that here. As the name implies it adds an entry to the context menu to search Wikipedia for highlighted text. The code can be found below. background.js

browser.contextMenus.create({
    id: "log-selection",
    title: "Search Wikipedia",
    contexts: ["selection"]
});

browser.contextMenus.onClicked.addListener(function(info, tab) {
    if (info.menuItemId == "log-selection") {
        var selectedText = info.selectionText;
        browser.storage.local.get({
                "language": "en",
                "tabBehaviour": "new",
                "tabActive": "yes"
            },
            function(item) {
                var language = item.language;
                var tabBehaviour = item.tabBehaviour;
                var tabActive = item.tabActive;

                var url = "https://" + language + ".wikipedia.org/w/index.php?search=" + encodeURIComponent(selectedText) + "&title=Special%3ASearch&fulltext=Search";
                if (tabBehaviour == "new") {
                    if (tabActive == "no") {
                        chrome.tabs.create({
                            url: url,
                            active: false
                        });
                    } else {
                        chrome.tabs.create({
                            url: url
                        });
                    }
                } else {
                    chrome.tabs.update({
                        url: url
                    });
                }
            });

    };
});

options.js

document.addEventListener('DOMContentLoaded', loadOptions);
document.querySelector('form').addEventListener('submit', saveOptions);

var storage = chrome.storage.local;
var language = document.querySelector('#language');
var tabBehaviour = document.querySelector('#tabBehaviour');
var tabActive = document.querySelector('#tabActive');

function saveOptions(e) {
    e.preventDefault();
    storage.set({
        'language': language.value,
        'tabBehaviour': tabBehaviour.value,
	'tabActive': tabActive.value
    }), function () {}
}

function loadOptions() {
    storage.get({
        'language': 'en',
        'tabBehaviour': 'new',
	'tabActive': 'yes'
    }, function (items) {
        language.value = items.language;
        tabBehaviour.value = items.tabBehaviour;
	tabActive.value = items.tabActive;
    });
}

options.html

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="options.css">
</head>

<body>
    <form>
        <p>
            <h3>Language</h3>
        </p>
        <select id="language" size="5">
			<option value="simple">Simple English</option>
			<option value="ar">العربية</option>
			<option value="id">Bahasa Indonesia</option>
			<option value="ms">Bahasa Melayu</option>
			<option value="bs">Bosanski</option>
			<option value="bg">Български</option>
			<option value="ca">Català</option>
			<option value="cs">Čeština</option>
			<option value="da">Dansk</option>
			<option value="de">Deutsch</option> 
			<option value="et">Eesti</option> 
			<option value="el">Ελληνικά</option> 
			<option value="en">English</option> 
			<option value="es">Español</option> 
			<option value="eo">Esperanto</option> 
			<option value="eu">Euskara</option>
			<option value="fr">Français</option>
			<option value="fa">فارسی</option> 
			<option value="gl">Galego</option> 
			<option value="ko">한국어</option> 
			<option value="he">Hrvatski</option> 
			<option value="it">Italiano</option> 
			<option value="ka">ქართული</option> 
			<option value="lv">Latviešu</option> 
			<option value="lt">Lietuvių</option> 
			<option value="hu">Magyar</option> 
			<option value="nl">Nederlands</option> 
			<option value="ja">日本語</option> 
			<option value="no">Norsk bokmål</option>
			<option value="nn">Norsk nynorsk</option> 
			<option value="pt">Português</option> 
			<option value="ro">Română</option> 
			<option value="ru">Русский</option> 
			<option value="sk">Slovenčina</option> 
			<option value="sl">Српски / srpski</option> 
			<option value="sh">Srpskohrvatski / српскохрватски</option> 
			<option value="fi">Suomi</option> 
			<option value="sv">Svenska</option> 
			<option value="th">ไทย</option>
			<option value="vi">Tiếng Việt</option> 
			<option value="uk">Українська</option> 
			<option value="zh">中文</option> 
			</select>
        <p>
            <h3>Tab behaviour</h3>
        </p>
        <select id="tabBehaviour" size="2">
			<option value="new">Open in new tab</option>
			<option value="old">Open in active tab</option>
			
			</select>
        <select id="tabActive" size="2">
			<option value="yes">New tab becomes active</option>
			<option value="no">New tab becomes not active</option>
			</select>
        <p><button type="submit" class="button">Save</button></p>
    </form>
    <script src="options.js"></script>
</body>

</html>

options.css

.button {
    border-style: hidden;
    background-color: rgb(76, 175, 80);
    padding: 0.5em 3em;
    color: white;
}

.button:hover {
    box-shadow: 0px 0px 20px #aaa;
}

manifest.json

{

    "description": "Select text. Right click. Search Wikipedia for the selected text.",
    "manifest_version": 2,
    "name": "Wikipedia Context Menu Search",
    "version": "1.2",
    "homepage_url": "https://diedrich.me/contact/",
    "icons": {
        "64": "icons/page-64.png"

    },

    "applications": {
        "gecko": {
            "id": "@wikipediacontextmenusearch",
            "strict_min_version": "52.0"
        }
    },

    "background": {
        "scripts": ["background.js"]
    },

    "options_ui": {
        "page": "options.html"
    },


    "permissions": [
        "tabs",
        "storage",
        "contextMenus"
    ]


}
⤧  Next post Let Ubuntu send you Emails if security updates are available ⤧  Previous post Star time lapse