Google: Link selector

Allows you to select Google links with the keyboard

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Google: Link selector
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  Allows you to select Google links with the keyboard
// @author       divide100
// @match        http*://www.google.ca/search?*
// @grant        GM_openInTab
// @require https://greasyfork.org/scripts/5679-wait-for-elements/code/Wait%20For%20Elements.js?version=46106
// ==/UserScript==
/* jshint -W097 */
'use strict';

var util = {
    log: function () {
        var args = [].slice.call(arguments);
        args.unshift('%c' + SCRIPT_NAME + ':', 'font-weight: bold;color: purple;');
        console.log.apply(console, args);
    },
    q: function(query, context) {
        return (context || document).querySelector(query);
    },
    qq: function(query, context) {
        return [].slice.call((context || document).querySelectorAll(query));
    }
};

var i = 0;
var results = util.qq('div.g', document.body);
results[i].style.border = "1px solid #4285f4";
results[i].style.borderRadius = "4px";

var SCRIPT_NAME = "Google Link Selector";

window.onkeypress = function(e) {
    switch(e.keyCode) {
            //w
        case 119:
            if(i > 0) {
                results[i--].style.border = "none";
            }
            break;
            //s
        case 115:
            if(i < results.length - 1) {
                results[i++].style.border = "none";
            }
            break;
            //enter
        case 13:
            if(e.shiftKey) {
                GM_openInTab(util.q('a', results[i]).href, false);
            }
            else {
                window.location.href = util.q('a', results[i]);
            }
            break;
    }
    results[i].style.border = "1px solid #4285f4";
    results[i].style.borderRadius = "4px";
    results[i].scrollIntoView();
};