Block Individual Requests

Hide individual HITs you're not interested in.

目前为 2015-02-16 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Block Individual Requests
  3. // @author Turksquatch
  4. // @version 0.0.5
  5. // @namespace http://www.turksquatch.com/
  6. // @homepage http://mturkforum.com/showthread.php?4441-New-Script-to-Block-Individual-Hits&p=56939
  7. // @description Hide individual HITs you're not interested in.
  8. // @include https://www.mturk.com/mturk/findhits*
  9. // @include https://www.mturk.com/mturk/searchbar*
  10. // @include https://www.mturk.com/mturk/viewsearchbar*
  11. // @include https://www.mturk.com/mturk/sortsearchbar*
  12. // @include https://www.mturk.com/mturk/sorthits*
  13. // @include https://www.mturk.com/mturk/viewhits*
  14. // ==/UserScript==
  15.  
  16. requestIndex = GM_getValue("requestIndex");
  17. if(!requestIndex) {
  18. //alert(requestIndex);
  19. requestIndex="";
  20. GM_setValue("requestIndex","");
  21. }
  22.  
  23.  
  24. function showUpdates() {
  25. updated = GM_getValue('requestUpdated');
  26. if (updated) {
  27. tables = document.evaluate("//table",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
  28. table = tables.snapshotItem(6);
  29. action = updated.split(',');
  30. rId = action[1].split('::')[0];
  31. rName = action[1].split('::')[1];
  32. div = document.createElement('div');
  33. div.id = 'updated';
  34. status = "<div class='message success'><h6><span id='alertboxHeader'>"+action[0]+" "+rName;
  35. if (action[0]=='Blocked') {
  36. status+=" <a style='font-size:80%;' href='javascript:unblockRequest(\""+rId+"\",\""+rName+"\");' title='Unblock this request'>undo</a>";
  37. }
  38. div.innerHTML = status + "</h6></span></div>";
  39. table.parentNode.insertBefore(div, table);
  40. GM_deleteValue('requestUpdated');
  41. }
  42. }
  43.  
  44. function hideHIT(element) {
  45. pa=element, step=0;
  46. while (step++ < 11) {
  47. ch = pa;
  48. pa = pa.parentNode;
  49. }
  50. pa.className = "rblocked";
  51. }
  52.  
  53. function unhideHIT(element) {
  54. pa=element, step=0;
  55. while (step++ < 11) {
  56. ch = pa;
  57. pa = pa.parentNode;
  58. }
  59. pa.className = "";
  60. }
  61.  
  62. function hideMatchingHITs() {
  63. var numBlocked=0;
  64. theseRequests = document.evaluate("//a[starts-with(@href,'/mturk/preview?groupId=')]",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
  65. for (i=0; i<theseRequests.snapshotLength; i++) {
  66. rLink = theseRequests.snapshotItem(i);
  67. rLink.parentNode.nowrap = false;
  68. rName = "x";
  69. rId = rLink.href.toString().split('=')[1];
  70. if (requestIndex.indexOf(rId) != -1 && location.href.indexOf(rId) == -1) {
  71. newElement = document.createElement('a');
  72. newElement.innerHTML = "&nbsp;<a style='font-size:80%;' href='javascript:unblockRequest(\""+rId+"\",\""+rName+"\");' title='Unblock this request'>unblock</a>";
  73. rLink.parentNode.insertBefore(newElement, rLink.nextSibling);
  74. hideHIT(rLink);
  75. numBlocked+=1;
  76. } else {
  77. newElement = document.createElement('a');
  78. newElement.innerHTML = "&nbsp;<a href='javascript:blockRequest(\""+rId+"\","+i+");' style='font-size:80%;' title='Block this request'>x</a>";
  79. rLink.parentNode.insertBefore(newElement, rLink.nextSibling);
  80. }
  81. }
  82. return numBlocked;
  83. }
  84.  
  85. unsafeWindow.unhideAllHITs = function () {
  86. theseRequests = document.evaluate("//a[starts-with(@href,'/mturk/preview?groupId=')]",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
  87. for (i=0; i<theseRequests.snapshotLength; i++) {
  88. unhideHIT(theseRequests.snapshotItem(i));
  89. }
  90. }
  91.  
  92. function showNumBlocked(numBlocked) {
  93. collapseAll = document.getElementById('collapseall');
  94. showAllBlocked = document.createElement("span");
  95. showAllBlocked.innerHTML = '&nbsp;&nbsp;<font color="#9ab8ef">|</font>&nbsp;&nbsp;<a href="javascript:unhideAllHITs();" class="footer_links" id="showrblocked">Show ' + numBlocked + ' rBlocked</a>';
  96. collapseAll.parentNode.insertBefore(showAllBlocked, collapseAll.nextSibling);
  97. }
  98.  
  99.  
  100. unsafeWindow.blockRequest = function (rId,i) {
  101. rName = "x";
  102. rEntry = rId+"::"+rName;
  103. requestIndex+= rEntry+"}{";
  104. if (confirm("Hide this HIT?")) {
  105. window.setTimeout(function() {
  106. GM_setValue("requestIndex", requestIndex);
  107. GM_setValue("requestUpdated", "Blocked,"+rEntry);
  108. }, 0);
  109. //window.setTimeout(GM_setValue, 0, "requestIndex", requestIndex);
  110. //window.setTimeout(GM_setValue, 0, "requestUpdated", "Blocked,"+rEntry);
  111. document.location.reload();
  112. }
  113. }
  114.  
  115.  
  116.  
  117.  
  118.  
  119. unsafeWindow.unblockRequest = function (rId,rName) {
  120. theseRequests = document.evaluate("//a[starts-with(@href,'/mturk/preview?groupId=')]",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
  121. rEntry = rId+"::"+rName;
  122. half = requestIndex.split(rId+"::");
  123. left = half[0];
  124. temp = half[1].split('}{');
  125. right = temp[1]+"}{";
  126. if (temp.length>1) {
  127. for (i=2;i<temp.length-1;i++) {
  128. right+=temp[i]+"}{";
  129. }
  130. }
  131. requestIndex = left + right;
  132. window.setTimeout(function() {
  133. GM_setValue("requestIndex", requestIndex);
  134. GM_setValue("requestUpdated", "Unblocked,"+rEntry);
  135. }, 0);
  136. //window.setTimeout(GM_setValue, 0, "requestIndex", requestIndex);
  137. //window.setTimeout(GM_setValue, 0, "requestUpdated", "Unblocked,"+rEntry);
  138. document.location.reload();
  139. }
  140.  
  141. function addGlobalStyle(css) {
  142. head = document.getElementsByTagName('head')[0];
  143. if (!head) { return; }
  144. style = document.createElement('style');
  145. style.type = 'text/css';
  146. style.innerHTML = css;
  147. head.appendChild(style);
  148. }
  149.  
  150. addGlobalStyle('.rblocked { display: none; }');
  151. showUpdates();
  152. showNumBlocked(hideMatchingHITs());