Custom Google Search for Mturk

A new window will open and search the highlighted words and saved words.

  1. // ==UserScript==
  2. // @name Custom Google Search for Mturk
  3. // @description A new window will open and search the highlighted words and saved words.
  4. // @author Cristo
  5. // @version 3.0
  6. // @grant GM_getValue
  7. // @grant GM_setValue
  8. // @include *
  9. // @copyright 2012+, You
  10. // @namespace https://greasyfork.org/users/1973
  11. // ==/UserScript==
  12.  
  13. //Hit the + key to enter text to save. Highlight what you want to search and hit the ~ key.
  14. //Saved words are stored until overwritten.
  15. //Update to window type and size.
  16. //If available screen size is less than 1/3 new window opens in a tab.
  17. //If over 1/3 it finds the largest side and opens new window there.
  18.  
  19. var FPK;
  20. if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
  21. FPK = 61;
  22. } else {
  23. FPK = 187;
  24. }
  25.  
  26. document.addEventListener("keydown", function(i) {
  27. if (i.keyCode == 192) {//~ Launchs Search
  28. launchIt();
  29. }
  30. if (i.keyCode == FPK) {//+ Adds terms
  31. var wordBank = prompt("Please enter search term to add");
  32. GM_setValue("search term", wordBank);
  33. }}, false);
  34. function launchIt() {
  35. var lighted = window.getSelection().toString();
  36. var newWidth;
  37. var newLeft;
  38. if (window.screenX > (screen.width - (window.screenX + window.outerWidth))) {
  39. newWidth = window.screenX;
  40. newLeft = "0";
  41. } else {
  42. newWidth = screen.width - (window.screenX + window.outerWidth);
  43. newLeft = window.screenX + window.outerWidth;
  44. }
  45. if (newWidth < screen.width/3) {
  46. window.open("http://www.google.com/search?q="+ lighted + " " + GM_getValue("search term"));
  47. } else {
  48. var windowTo = 'width=' + newWidth;
  49. windowTo += ', height=' + screen.height;
  50. windowTo += ', top=' + "0";
  51. windowTo += ', left=' + newLeft;
  52. window.open("http://www.google.com/search?q="+ lighted + " " + GM_getValue("search term"), "name", windowTo);
  53. }
  54. }