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.

当前为 2015-09-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Google & YouTube - Exact Search Hotkey
  3. // @namespace GYESH
  4. // @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.
  5. // @run-at document-start
  6. // @include htt*://*.google.*/*
  7. // @include htt*://google.*/*
  8. // @include htt*://*.youtube.*/*
  9. // @include htt*://youtube.*/*
  10. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  11. // @author drhouse
  12. // @icon https://www.google.ca/images/google_favicon_128.png
  13. // @version 1.1
  14. // ==/UserScript==
  15.  
  16. $(document).ready(function () {
  17. var text, nquote, lastChar, replit;
  18.  
  19. function getSelectionText() {
  20. text = "";
  21. if (window.getSelection) {
  22. text = window.getSelection().toString();
  23. } else if (document.selection && document.selection.type != "Control") {
  24. text = document.selection.createRange().text;
  25. }
  26. lastChar = text.substr(text.length - 1);
  27. while (lastChar == ' '){
  28. text = text.slice(0,-1);
  29. lastChar = text.substr(text.length - 1);
  30. }
  31. nquote = '"'+text+'"';
  32. return nquote;
  33. }
  34.  
  35. $("#lst-ib").keypress(function( event ) { //Google Search
  36. if ( event.which == 43 ) { //NumpadAdd key
  37. event.preventDefault();
  38. console.log(getSelectionText());
  39. replit = $("#lst-ib").val().replace(text,getSelectionText());
  40. $("#lst-ib").val(replit);
  41. }
  42. });
  43. $("#masthead-search-term").keypress(function( event ) { //YouTube Search
  44. if ( event.which == 43 ) { //NumpadAdd key
  45. event.preventDefault();
  46. console.log(getSelectionText());
  47. replit = $("#masthead-search-term").val().replace(text,getSelectionText());
  48. $("#masthead-search-term").val(replit);
  49. }
  50. });
  51. });