Google & YouTube - Exact Search Hotkey

Simply press the NumpadAdd hotkey on your selected term(s) in the search box and they will be auto-encased in quotes, using Google's "exact search" boolean syntax - no more tedious cursor positioning or unrelated search results.

目前為 2021-12-17 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Google & YouTube - Exact Search Hotkey
// @namespace    GYESH
// @description  Simply press the NumpadAdd hotkey on your selected term(s) in the search box and they will be auto-encased in quotes, using Google's "exact search" boolean syntax - no more tedious cursor positioning or unrelated search results.
// @run-at       document-start
// @include      htt*://*.google.*/*
// @include      htt*://google.*/*
// @include      htt*://*.youtube.*/*
// @include      htt*://youtube.*/*
// @include      htt*://*.bing.*/*
// @include      htt*://bing.*/*
// @require      http://code.jquery.com/jquery-3.4.1.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.16.0/polyfill.js
// @author       drhouse
// @icon         https://www.google.ca/images/google_favicon_128.png
// @version      4.0
// @license      CC-BY-NC-SA-4.0
// ==/UserScript==

jQuery(function($){
    var text, nquote, lastChar, replit;

    function getSelectionText() {
        text = "";
        if (window.getSelection) {
            text = window.getSelection().toString();
        } else if (document.selection && document.selection.type != "Control") {
            text = document.selection.createRange().text;
        }
        lastChar = text.substr(text.length - 1);
        while (lastChar == ' '){
            text = text.slice(0,-1);
            lastChar = text.substr(text.length - 1);
        }
        nquote = '"'+text+'"';
        return nquote;
    }

    $("input").keypress(function( event ) { //Google Search
        if ( event.which == 43 ) { //NumpadAdd key
            event.preventDefault();
            console.log(getSelectionText());
            replit = $("input").val().replace(text,getSelectionText());
            $("input").val(replit);
        }
    });
    
    
});