Google & YouTube nQuote

A must-have tool that saves time and performs more efficient searches. Simply press the NumpadAdd hotkey on your selected search box term(s) and they will be auto-encased in quotation marks, taking advantage of Google's powerful 'exact search' syntax - no more tedious cursor positioning or unrelated search results.

目前為 2015-09-06 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Google & YouTube nQuote
// @namespace    GYNQ
// @description  A must-have tool that saves time and performs more efficient searches. Simply press the NumpadAdd hotkey on your selected search box term(s) and they will be auto-encased in quotation marks, taking advantage of Google's powerful 'exact search' 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.*/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @author       drhouse
// @version      1.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);
		}
	});
});