Greasy Fork is available in English.

Linky

Turn selected areas inside a Mturk hit into a google link.

  1. // ==UserScript==
  2. // @name Linky
  3. // @version 0.6
  4. // @description Turn selected areas inside a Mturk hit into a google link.
  5. // @author Cristo
  6. // @include *
  7. // @grant GM_getValue
  8. // @grant GM_setValue
  9. // @grant GM_deleteValue
  10. // @copyright 2012+, You
  11. // @namespace https://greasyfork.org/users/1973
  12. // ==/UserScript==
  13.  
  14. //Turn selected areas inside a hit into a google link.
  15. //Highlight words you would like to add to a google search and press + on the number pad, repeat as needed.
  16. //For best results highlight as little as needed
  17. //Press - on the number pad to delete saved data.
  18. var build = [];
  19. var savedData = [];
  20. if(GM_getValue('taginfo')){
  21. for(var p = 0; p < GM_getValue('taginfo').length; p++){
  22. savedData.push(JSON.parse(GM_getValue('taginfo')[p]));
  23. }
  24. }
  25. if (window.location != window.parent.location === true) {
  26. console.log('Yes Frame');
  27. linkMaker();
  28. } else if (!document.getElementsByTagName('iframe') [0] && document.getElementsByName('hitForm') [1]) {
  29. console.log('No Frame');
  30. linkMaker();
  31. } else {
  32. console.log('No Run');
  33. }
  34.  
  35. function finder() {
  36. var ti;
  37. var lightText = window.getSelection();
  38. var stringText = lightText.toString();
  39. var textElement = lightText.anchorNode.parentNode;
  40. var elementString = textElement.textContent;
  41. var stringStart = elementString.indexOf(stringText);
  42. var stringEnd = stringText.length;
  43. var textTagType = textElement.tagName;
  44. if (lightText.anchorNode != lightText.focusNode) {
  45. alert('Multiple nodes selected, please break up selection');
  46. } else {
  47. var simTags = document.getElementsByTagName(textTagType);
  48. for (var t = 0; t < simTags.length; t++) {
  49. if (simTags[t] == textElement) {
  50. ti = t;
  51. }
  52. }
  53. }
  54. var data = new Object();
  55. data.Tag = textTagType;
  56. data.Tagindex = ti;
  57. data.First = stringStart;
  58. data.Last = elementString.length - (stringStart + stringText.length);
  59. build.push(JSON.stringify(data));
  60. GM_setValue('taginfo', build);
  61. }
  62. function linkMaker() {
  63. if (GM_getValue('taginfo') && document.getElementsByTagName(savedData[0].Tag) [savedData[0].Tagindex]) {
  64. var currentWords = [];
  65. var aLinkAnc = document.getElementsByTagName(savedData[0].Tag) [savedData[0].Tagindex];
  66. for (var s = 0; s < savedData.length; s++) {
  67. if (document.getElementsByTagName(savedData[s].Tag) [savedData[s].Tagindex]) {
  68. var sTags = document.getElementsByTagName(savedData[s].Tag) [savedData[s].Tagindex];
  69. var sTIn = sTags.textContent;
  70. var cutText = sTIn;
  71. var owb = savedData[s].First;
  72. var owe = savedData[s].Last;
  73. if (owb > 0) {
  74. var frontCut = sTIn.substring(0, owb - 1);
  75. cutText = cutText.replace(frontCut, '');
  76. }
  77. if (owe > 0) {
  78. var backCut = sTIn.substring(sTIn.length - (owe - 1), sTIn.length);
  79. cutText = cutText.replace(backCut, '');
  80. }
  81. currentWords.push(cutText);
  82. }
  83. }
  84. var wordString = currentWords.toString().replace(/,/g, ' ');
  85. var cleanWords = wordString.replace(/[^a-zA-Z0-9\s]/g, ' ');
  86. var searchWords = cleanWords.replace(/\s/g, '%20');
  87. var link = document.createElement('a');
  88. link.target = '_blank';
  89. link.href = 'http://www.google.com/search?q=' + searchWords;
  90. link.innerHTML = cleanWords;
  91. aLinkAnc.parentNode.insertBefore(link, aLinkAnc.nextSibling);
  92. }
  93. }
  94. document.addEventListener('keydown', function (i) {
  95. if (i.keyCode == 107) { //+ Adds terms
  96. finder();
  97. }
  98. if (i.keyCode == 109) { //- Delete terms
  99. GM_deleteValue('taginfo');
  100. }
  101. }, false);