Advertisement
Guest User

Untitled

a guest
Jul 10th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Yoder
  3. // @author Sasquatch
  4. // @version 1.0.0
  5. // @namespace http://www.turksquatch.com/
  6. // @homepage http://www.turksquatch.com/
  7. // @description Tame the internet.
  8. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
  9. // @include https://www.mturkcontent.com/*
  10. // @include https://www.google.com/*
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. //to do - highlight search term, add functionality to given domain
  15.  
  16. var autosubmit = false;
  17.  
  18. String.prototype.strip_html = function() {
  19. var tmp = document.createElement('div');
  20. tmp.innerHTML = this;
  21. return tmp.textContent || tmp.innerText;
  22. }
  23.  
  24. function copyText(evt) {
  25. if (evt.keyCode == 59 && evt.ctrlKey) {
  26. var selectedText = getText();
  27. if (selectedText && selectedText != '') {
  28. sendText(selectedText);
  29. } else {
  30. alert('Nothing selected');
  31. }
  32. }
  33. if (evt.keyCode == 222 && evt.ctrlKey) {
  34. sendText("N/A");
  35. }
  36. }
  37.  
  38. function getText() {
  39. var userSelection = '';
  40. if (typeof window.getSelection != 'undefined') {
  41. var sel = window.getSelection();
  42. if (sel.rangeCount) {
  43. var container = document.createElement('div');
  44. for (var i = 0, len = sel.rangeCount; i < len; ++i) {
  45. container.appendChild(sel.getRangeAt(i).cloneContents());
  46. }
  47. userSelection = container.innerHTML.strip_html();
  48. }
  49. } else if (typeof document.selection != 'undefined') {
  50. if (document.selection.type == 'Text') {
  51. userSelection = document.selection.createRange().htmlText.strip_html();
  52. }
  53. }
  54. return userSelection;
  55. }
  56.  
  57. function sendText(textVar) {
  58. window.opener.postMessage({ securitycheck: "fromgooglesearch", dataval: textVar }, "*");
  59. }
  60.  
  61. function highlightTerm(term) {
  62. $('#ires>*').each(function(){
  63. if ($(this).html().indexOf(term) > -1) {
  64. var regex = new RegExp(term, 'gi');
  65. $(this).html($(this).html().replace(regex ,'<span style=\'background:yellow\'>'+term+'</span>' ));
  66. }
  67. });
  68. }
  69.  
  70. if (window.location.href.indexOf('mturkcontent') > -1) {
  71. document.getElementById('mturk_form').onsubmit = function() {
  72. searchWin.close();
  73. }
  74. window.addEventListener('message', function(e) {
  75. if (e.data.securitycheck === 'fromgooglesearch') {
  76. self.focus();
  77. document.getElementById('web_url').focus();
  78. document.getElementById('web_url').value = e.data.dataval;
  79. if (autosubmit) {
  80. document.getElementById('mturk_form').submit();
  81. }
  82. }
  83. }, false);
  84. var domainName = document.getElementsByTagName('td')[1].innerHTML.trim();
  85. var directUrl = 'http://' + domainName;
  86. var googleBase = 'https://www.google.com/search?q=';
  87. var queryString = encodeURIComponent(domainName);
  88. var searchUrl = googleBase + queryString;
  89. var w = screen.availWidth/2;
  90. var h = screen.availHeight;
  91. searchWin = window.open(searchUrl, 'Search Page', 'width='+w+', height='+h+', scrollbars=yes, toolbar=yes');
  92. searchWin.moveTo(w,0);
  93. } else {
  94. if (window.location.href.indexOf('google.com') > -1) {
  95. var searchTerm = window.location.href.split('q=')[1].split('&')[0];
  96. }
  97. highlightTerm(searchTerm);
  98. document.onkeydown = copyText;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement