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-12 提交的版本,查看 最新版本

  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.1c
  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. GM_setValue("scraper_ignore_list","nothing blocked yet");
  41. }
  42. if ( GM_getValue("scraper_ignore_list") ){
  43. ignore_list = GM_getValue("scraper_ignore_list").split('^');
  44. console.log(ignore_list);
  45. }
  46.  
  47. // check ignore list for requester name and HIT title
  48. function ignore_check(r,t){
  49. var tempList = ignore_list.map(function(item) { return item.toLowerCase(); });
  50. var foundR = -1;
  51. var foundT = -1;
  52. foundR = tempList.indexOf(r.toLowerCase());
  53. foundT = tempList.indexOf(t.toLowerCase());
  54. var found = foundR == -1 && foundT == -1;
  55. return found; // returns false (making !(ignore_check(x,y)) true) if HIT should be blocked, returns true if it shouldn't be blocked
  56. }
  57.  
  58. // identify HITs, requesters, and titles
  59. var $requester = $('a[href^="/mturk/searchbar?selectedSearchType=hitgroups&requester"]');
  60. var $title = $('a[class="capsulelink"]');
  61. 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
  62. console.log("HIT capsules identified: " + $hitcapsule.length);
  63.  
  64. // hide blocked hits
  65. var blockedcount = 0;
  66. function hideBlocked(){
  67. console.log("starting to block, total HITs to check: " + $requester.length);
  68. blockedcount = 0;
  69. for (var j = 0; j < $requester.length; j++){
  70. var requester_name = $requester.eq(j).text().trim();
  71. var title = $title.eq(j).text().trim();
  72. console.log("HIT " + (j+1) + " detected. Requester: " + requester_name + ", Title: " + title);
  73. var hitcapsule = $hitcapsule.eq(j);
  74. if (!ignore_check(requester_name,title)){ // hide hit if requester name or hit title is in your blocklist
  75. hitcapsule.hide();
  76. blockedcount++;
  77. console.log("blocked HIT " + (j+1) );
  78. }
  79. }
  80. console.log("Total HITs blocked: " + blockedcount);
  81. }
  82.  
  83. $(document).ready(hideBlocked()); // initiate hiding first time when page loads
  84.  
  85. // unhide blocked hits
  86. function showBlocked(){
  87. console.log("starting to un-hide");
  88. for (var j = 0; j < $requester.length; j++){
  89. var hitcapsule = $hitcapsule.eq(j);
  90. hitcapsule.show();
  91. }
  92. }
  93.  
  94. // open blocklist editor
  95. var edit_blocks = document.createElement("span");
  96. edit_blocks.innerHTML = '&nbsp;&nbsp;<font color="#9ab8ef">|</font>&nbsp;&nbsp;<a href="#" class="footer_links" id="blocklist_edit_link">Edit Blocklist</a>';
  97. edit_blocks.onclick = function(){
  98. console.log("opened blocklist editor");
  99. var textarea = $("#blocklist_text");
  100. var text = "";
  101. for (var i in ignore_list){
  102. text += ignore_list[i]+"^";
  103. }
  104. textarea.text(text.substring(0, text.length - 1));
  105. $("#blocklist_div").show();
  106. };
  107.  
  108. // show/hide blocked hits
  109. var showAllBlocked = document.createElement("span");
  110. showAllBlocked.innerHTML = '&nbsp;&nbsp;<font color="#9ab8ef">|</font>&nbsp;&nbsp;<a href="#" class="footer_links" id="showblocked">Show ' + blockedcount + ' Blocked</a>';
  111. showAllBlocked.onclick = function(){
  112. if ( document.getElementById('showblocked').innerHTML.indexOf("Show") > -1 ) {
  113. console.log("Un-hiding blocked hits - " + document.getElementById('showblocked').innerHTML );
  114. showBlocked();
  115. document.getElementById('showblocked').innerHTML = "Hide " + blockedcount + " Blocked";
  116. }
  117. else if ( document.getElementById('showblocked').innerHTML.indexOf("Hide") > -1 ) {
  118. console.log("Re-hiding blocked hits - " + document.getElementById('showblocked').innerHTML );
  119. hideBlocked();
  120. document.getElementById('showblocked').innerHTML = "Show " + blockedcount + " Blocked";
  121. }
  122. };
  123.  
  124. // add edit and show/hide links to page
  125. var collapseAll = document.getElementById('collapseall');
  126. collapseAll.parentNode.insertBefore(showAllBlocked, collapseAll.nextSibling);
  127. collapseAll.parentNode.insertBefore(edit_blocks, collapseAll.nextSibling);
  128.  
  129.  
  130.  
  131. // For editing the blocklist
  132. var blocklistdiv = document.createElement('div');
  133. var blocklisttextarea = document.createElement('textarea');
  134.  
  135. blocklistdiv.style.position = 'fixed';
  136. blocklistdiv.style.width = '500px';
  137. blocklistdiv.style.height = '255px';
  138. blocklistdiv.style.left = '50%';
  139. blocklistdiv.style.right = '50%';
  140. blocklistdiv.style.margin = '-250px 0px 0px -250px';
  141. blocklistdiv.style.top = '300px';
  142. blocklistdiv.style.padding = '5px';
  143. blocklistdiv.style.border = '2px';
  144. blocklistdiv.style.backgroundColor = 'black';
  145. blocklistdiv.style.color = 'white';
  146. blocklistdiv.style.zIndex = '100';
  147. blocklistdiv.setAttribute('id','blocklist_div');
  148. blocklistdiv.style.display = 'none';
  149.  
  150. blocklisttextarea.style.padding = '2px';
  151. blocklisttextarea.style.width = '500px';
  152. blocklisttextarea.style.height = '180px';
  153. blocklisttextarea.title = 'Block list';
  154. blocklisttextarea.setAttribute('id','blocklist_text');
  155.  
  156. 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.)';
  157. blocklistdiv.style.fontSize = '12px';
  158. blocklistdiv.appendChild(blocklisttextarea);
  159.  
  160. var save_BLbutton = document.createElement('button');
  161. var cancel_BLbutton = document.createElement('button');
  162.  
  163. save_BLbutton.textContent = 'Save';
  164. save_BLbutton.setAttribute('id', 'save_BLblocklist');
  165. save_BLbutton.style.height = '18px';
  166. save_BLbutton.style.width = '100px';
  167. save_BLbutton.style.fontSize = '10px';
  168. save_BLbutton.style.paddingLeft = '3px';
  169. save_BLbutton.style.paddingRight = '3px';
  170. save_BLbutton.style.backgroundColor = 'white';
  171. save_BLbutton.style.marginLeft = '5px';
  172.  
  173. cancel_BLbutton.textContent = 'Cancel';
  174. cancel_BLbutton.setAttribute('id', 'cancel_BLblocklist');
  175. cancel_BLbutton.style.height = '18px';
  176. cancel_BLbutton.style.width = '100px';
  177. cancel_BLbutton.style.fontSize = '10px';
  178. cancel_BLbutton.style.paddingLeft = '3px';
  179. cancel_BLbutton.style.paddingRight = '3px';
  180. cancel_BLbutton.style.backgroundColor = 'white';
  181. cancel_BLbutton.style.marginLeft = '5px';
  182.  
  183. blocklistdiv.appendChild(save_BLbutton);
  184. blocklistdiv.appendChild(cancel_BLbutton);
  185.  
  186. save_BLbutton.addEventListener("click", function() {save_BLblocklist();}, false);
  187. cancel_BLbutton.addEventListener("click", function() {$("#blocklist_div").hide();}, false);
  188. document.body.insertBefore(blocklistdiv, document.body.firstChild);
  189.  
  190.  
  191. function save_BLblocklist() {
  192. console.log("Save");
  193. var textarea = $("#blocklist_text");
  194. var text = textarea.val();
  195. var block_list = text.split("^");
  196. var trimmed_list = [];
  197. for (var requester in block_list){
  198. if (block_list[requester].trim().length != 0)
  199. trimmed_list.push(block_list[requester].toLowerCase().trim());
  200. }
  201. console.log(trimmed_list);
  202. GM_setValue("scraper_ignore_list",trimmed_list.join('^'));
  203. ignore_list = GM_getValue("scraper_ignore_list").split('^');
  204. console.log("Save complete: ");
  205. console.log(ignore_list);
  206. $("#blocklist_div").hide();
  207. }