Duckduckgo quick bang

Quick jump to startpage & google

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Duckduckgo quick bang
// @namespace    http://taiho.moe/
// @version      0.1
// @description  Quick jump to startpage & google
// @author       swordfeng
// @match        https://duckduckgo.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const searchBars = $('ul#duckbar_static');
    if (searchBars) {
        appendToSearchBar(searchBars[0]);
    }
})();

function appendToSearchBar(bar) {
    appendBang(bar, 's');
    appendBang(bar, 'g');
}

function appendBang(bar, bang) {
    const bangLink = document.createElement('a');
    bangLink.className = 'zcm__link';
    bangLink.innerHTML = '!' + bang;
    bangLink.href = '#';
    bangLink.addEventListener('click', () => {
        const search = '!' + bang + ' ' + getSearch();
        window.location.search = '?q=' + encodeURIComponent(search);
    });
    const bangItem = document.createElement('li');
    bangItem.className = 'zcm__item';

    bangItem.appendChild(bangLink);
    bar.appendChild(bangItem);
}

function getSearch() {
    const searchBox = $('input[name="q"]')[0];
    return searchBox.value;
}