CH Block Using HIT Scraper's Blocklist

Block requesters and HITs on regular MTurk search results pages using your blocklist from 'HIT Scraper With Export'.

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

  1. // ==UserScript==
  2. // @name CH Block Using HIT Scraper's Blocklist
  3. // @description Block requesters and HITs on regular MTurk search results pages using your blocklist from 'HIT Scraper With Export'.
  4. // @version 1.0c
  5. // @author clickhappier
  6. // @namespace clickhappier
  7. // @include https://www.mturk.com/mturk/findhits*
  8. // @include https://www.mturk.com/mturk/viewhits*
  9. // @include https://www.mturk.com/mturk/sorthits*
  10. // @include https://www.mturk.com/mturk/searchbar*selectedSearchType=hitgroups*
  11. // @include https://www.mturk.com/mturk/viewsearchbar*selectedSearchType=hitgroups*
  12. // @include https://www.mturk.com/mturk/sortsearchbar*HITGroup*
  13. // @include https://www.mturk.com/mturk/preview*
  14. // @include https://www.mturk.com/mturk/return*
  15. // @exclude https://www.mturk.com/*hit_scraper
  16. // @require http://code.jquery.com/jquery-latest.min.js
  17. // @grant GM_log
  18. // ==/UserScript==
  19.  
  20. // adaptations from Kerek+Tjololo's 'HIT Scraper WITH EXPORT': https://greasyfork.org/en/scripts/2002-hit-scraper-with-export
  21.  
  22.  
  23. // use localStorage instead of GM's storage
  24. if (!this.GM_getValue || (this.GM_getValue.toString && this.GM_getValue.toString().indexOf("not supported")>-1)) { // these grants aren't declared, so the answer's always no
  25. this.GM_getValue=function (key,def) {
  26. return localStorage[key] || def;
  27. };
  28. this.GM_setValue=function (key,value) {
  29. return localStorage[key]=value;
  30. };
  31. this.GM_deleteValue=function (key) {
  32. return localStorage.removeItem(key);
  33. };
  34. }
  35.  
  36. // load ignore list
  37. console.log("blocklist script loaded");
  38. var ignore_list;
  39. if (GM_getValue("scraper_ignore_list")){
  40. ignore_list = GM_getValue("scraper_ignore_list").split('^');
  41. console.log(ignore_list);
  42. }
  43.  
  44. // check ignore list for requester name and HIT title
  45. function ignore_check(r,t){
  46. var tempList = ignore_list.map(function(item) { return item.toLowerCase(); });
  47. var foundR = -1;
  48. var foundT = -1;
  49. foundR = tempList.indexOf(r.toLowerCase());
  50. foundT = tempList.indexOf(t.toLowerCase());
  51. var found = foundR == -1 && foundT == -1;
  52. return found; // returns false (making !(ignore_check(x,y)) true) if HIT should be blocked, returns true if it shouldn't be blocked
  53. }
  54.  
  55. // identify HITs, requesters, and titles
  56. var $requester = $('a[href^="/mturk/searchbar?selectedSearchType=hitgroups&requester"]');
  57. var $title = $('a[class="capsulelink"]');
  58. var $hitcapsule = $("table[width='100%'][cellspacing='0'][cellpadding='0'][border='0'][height='100%']").parent(); // using parent td for compatibility with 'mmmturkeybacon Color-Coded Search' / 'mmmturkeybacon Color-Coded Search with Checkpoints', which hides/shows the table inside the parent td
  59. console.log("HIT capsules identified: " + $hitcapsule.length);
  60.  
  61. // hide blocked hits
  62. var blockedcount = 0;
  63. function hideBlocked(){
  64. console.log("starting to block, total HITs to check: " + $requester.length);
  65. blockedcount = 0;
  66. for (var j = 0; j < $requester.length; j++){
  67. var requester_name = $requester.eq(j).text().trim();
  68. var title = $title.eq(j).text().trim();
  69. console.log("HIT " + (j+1) + " detected. Requester: " + requester_name + ", Title: " + title);
  70. var hitcapsule = $hitcapsule.eq(j);
  71. if (!ignore_check(requester_name,title)){ // hide hit if requester name or hit title is in your blocklist
  72. hitcapsule.hide();
  73. blockedcount++;
  74. console.log("blocked HIT " + (j+1) );
  75. }
  76. }
  77. console.log("Total HITs blocked: " + blockedcount);
  78. }
  79.  
  80. $(document).ready(hideBlocked()); // initiate hiding first time when page loads
  81.  
  82. // unhide blocked hits
  83. function showBlocked(){
  84. console.log("starting to un-hide");
  85. for (var j = 0; j < $requester.length; j++){
  86. var hitcapsule = $hitcapsule.eq(j);
  87. hitcapsule.show();
  88. }
  89. }
  90.  
  91. // open blocklist editor
  92. var edit_blocks = document.createElement("span");
  93. edit_blocks.innerHTML = '&nbsp;&nbsp;<font color="#9ab8ef">|</font>&nbsp;&nbsp;<a href="#" class="footer_links" id="blocklist_edit_link">Edit Blocklist</a>';
  94. edit_blocks.onclick = function(){
  95. console.log("opened blocklist editor");
  96. var textarea = $("#blocklist_text");
  97. var text = "";
  98. for (var i in ignore_list){
  99. text += ignore_list[i]+"^";
  100. }
  101. textarea.text(text.substring(0, text.length - 1));
  102. $("#blocklist_div").show();
  103. };
  104.  
  105. // show/hide blocked hits
  106. var showAllBlocked = document.createElement("span");
  107. showAllBlocked.innerHTML = '&nbsp;&nbsp;<font color="#9ab8ef">|</font>&nbsp;&nbsp;<a href="#" class="footer_links" id="showblocked">Show ' + blockedcount + ' Blocked</a>';
  108. showAllBlocked.onclick = function(){
  109. if ( document.getElementById('showblocked').innerHTML.indexOf("Show") > -1 ) {
  110. console.log("Un-hiding blocked hits - " + document.getElementById('showblocked').innerHTML );
  111. showBlocked();
  112. document.getElementById('showblocked').innerHTML = "Hide " + blockedcount + " Blocked";
  113. }
  114. else if ( document.getElementById('showblocked').innerHTML.indexOf("Hide") > -1 ) {
  115. console.log("Re-hiding blocked hits - " + document.getElementById('showblocked').innerHTML );
  116. hideBlocked();
  117. document.getElementById('showblocked').innerHTML = "Show " + blockedcount + " Blocked";
  118. }
  119. };
  120.  
  121. // add edit and show/hide links to page
  122. var collapseAll = document.getElementById('collapseall');
  123. collapseAll.parentNode.insertBefore(showAllBlocked, collapseAll.nextSibling);
  124. collapseAll.parentNode.insertBefore(edit_blocks, collapseAll.nextSibling);
  125.  
  126.  
  127.  
  128. // For editing the blocklist
  129. var blocklistdiv = document.createElement('div');
  130. var blocklisttextarea = document.createElement('textarea');
  131.  
  132. blocklistdiv.style.position = 'fixed';
  133. blocklistdiv.style.width = '500px';
  134. blocklistdiv.style.height = '255px';
  135. blocklistdiv.style.left = '50%';
  136. blocklistdiv.style.right = '50%';
  137. blocklistdiv.style.margin = '-250px 0px 0px -250px';
  138. blocklistdiv.style.top = '300px';
  139. blocklistdiv.style.padding = '5px';
  140. blocklistdiv.style.border = '2px';
  141. blocklistdiv.style.backgroundColor = 'black';
  142. blocklistdiv.style.color = 'white';
  143. blocklistdiv.style.zIndex = '100';
  144. blocklistdiv.setAttribute('id','blocklist_div');
  145. blocklistdiv.style.display = 'none';
  146.  
  147. blocklisttextarea.style.padding = '2px';
  148. blocklisttextarea.style.width = '500px';
  149. blocklisttextarea.style.height = '180px';
  150. blocklisttextarea.title = 'Block list';
  151. blocklisttextarea.setAttribute('id','blocklist_text');
  152.  
  153. blocklistdiv.textContent = 'This blocklist is shared with HIT Scraper With Export. Separate requester names and HIT titles with the ^ character. After clicking "Save", you\'ll need to refresh the page to apply the changes. (And refresh any other tabs, including HIT Scraper tabs, that you want to reflect the changes.)';
  154. blocklistdiv.style.fontSize = '12px';
  155. blocklistdiv.appendChild(blocklisttextarea);
  156.  
  157. var save_BLbutton = document.createElement('button');
  158. var cancel_BLbutton = document.createElement('button');
  159.  
  160. save_BLbutton.textContent = 'Save';
  161. save_BLbutton.setAttribute('id', 'save_BLblocklist');
  162. save_BLbutton.style.height = '18px';
  163. save_BLbutton.style.width = '100px';
  164. save_BLbutton.style.fontSize = '10px';
  165. save_BLbutton.style.paddingLeft = '3px';
  166. save_BLbutton.style.paddingRight = '3px';
  167. save_BLbutton.style.backgroundColor = 'white';
  168. save_BLbutton.style.marginLeft = '5px';
  169.  
  170. cancel_BLbutton.textContent = 'Cancel';
  171. cancel_BLbutton.setAttribute('id', 'cancel_BLblocklist');
  172. cancel_BLbutton.style.height = '18px';
  173. cancel_BLbutton.style.width = '100px';
  174. cancel_BLbutton.style.fontSize = '10px';
  175. cancel_BLbutton.style.paddingLeft = '3px';
  176. cancel_BLbutton.style.paddingRight = '3px';
  177. cancel_BLbutton.style.backgroundColor = 'white';
  178. cancel_BLbutton.style.marginLeft = '5px';
  179.  
  180. blocklistdiv.appendChild(save_BLbutton);
  181. blocklistdiv.appendChild(cancel_BLbutton);
  182.  
  183. save_BLbutton.addEventListener("click", function() {save_BLblocklist();}, false);
  184. cancel_BLbutton.addEventListener("click", function() {$("#blocklist_div").hide();}, false);
  185. document.body.insertBefore(blocklistdiv, document.body.firstChild);
  186.  
  187.  
  188. function save_BLblocklist() {
  189. console.log("Save");
  190. var textarea = $("#blocklist_text");
  191. var text = textarea.val();
  192. var block_list = text.split("^");
  193. var trimmed_list = [];
  194. for (var requester in block_list){
  195. if (block_list[requester].trim().length != 0)
  196. trimmed_list.push(block_list[requester].toLowerCase().trim());
  197. }
  198. console.log(trimmed_list);
  199. GM_setValue("scraper_ignore_list",trimmed_list.join('^'));
  200. ignore_list = GM_getValue("scraper_ignore_list").split('^');
  201. console.log("Save complete: ");
  202. console.log(ignore_list);
  203. $("#blocklist_div").hide();
  204. }