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.

当前为 2016-06-24 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @author       drhouse
// @icon         https://www.google.ca/images/google_favicon_128.png
// @version      2.0
// ==/UserScript==

$(document).ready(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;
	}

	$("#lst-ib").keypress(function( event ) { //Google Search
		if ( event.which == 43 ) { //NumpadAdd key
			event.preventDefault();
			console.log(getSelectionText());
			replit = $("#lst-ib").val().replace(text,getSelectionText());
			$("#lst-ib").val(replit);
		}
	});
	
	$("#masthead-search-term").keypress(function( event ) { //YouTube Search
		if ( event.which == 43 ) { //NumpadAdd key
			event.preventDefault();
			console.log(getSelectionText());
			replit = $("#masthead-search-term").val().replace(text,getSelectionText());
			$("#masthead-search-term").val(replit);
		}
	});
	
	    $("#sb_form_q").keypress(function( event ) { //Bing Search
		if ( event.which == 43 ) { //NumpadAdd key
			event.preventDefault();
			console.log(getSelectionText());
			replit = $("#sb_form_q").val().replace(text,getSelectionText());
			$("#sb_form_q").val(replit);
		}
	});
});