StartPage shortcuts

Add some shortcuts in StartPage's pages.

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         StartPage shortcuts
// @namespace    https://wiki.gslin.org/wiki/StartPage_shortcuts
// @version      0.20190216.0
// @description  Add some shortcuts in StartPage's pages.
// @author       Gea-Suan Lin
// @match        https://www.startpage.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    document.addEventListener('keyup', function(event) {
        if ('input' === document.activeElement.tagName.toLowerCase()) {
            return;
        }
        if ('d' === event.key) {
            let q = document.getElementById('query').value;
            let q_encoded = encodeURIComponent(q).replace(/%20/g, '+');
            let url = 'https://duckduckgo.com/?ia=&q=' + q_encoded;
            document.location = url;
        }
        if ('g' === event.key) {
            let q = document.getElementById('query').value;
            let q_encoded = encodeURIComponent(q).replace(/%20/g, '+');
            let url = 'https://www.google.com/search?q=' + q_encoded;
            document.location = url;
        }
    });
})();