Duckduckgo quick bang

Quick jump to startpage & google

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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;
}