您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Block requesters and HITs on regular MTurk search results pages using your blocklist from 'HIT Scraper With Export'.
当前为
- // ==UserScript==
- // @name CH Block Using HIT Scraper's Blocklist
- // @description Block requesters and HITs on regular MTurk search results pages using your blocklist from 'HIT Scraper With Export'.
- // @version 1.1c
- // @author clickhappier
- // @namespace clickhappier
- // @include https://www.mturk.com/mturk/findhits*
- // @include https://www.mturk.com/mturk/viewhits*
- // @include https://www.mturk.com/mturk/sorthits*
- // @include https://www.mturk.com/mturk/searchbar*selectedSearchType=hitgroups*
- // @include https://www.mturk.com/mturk/viewsearchbar*selectedSearchType=hitgroups*
- // @include https://www.mturk.com/mturk/sortsearchbar*HITGroup*
- // @include https://www.mturk.com/mturk/preview*
- // @include https://www.mturk.com/mturk/return*
- // @exclude https://www.mturk.com/*hit_scraper
- // @require http://code.jquery.com/jquery-latest.min.js
- // @grant GM_log
- // ==/UserScript==
- // adaptations from Kerek+Tjololo's 'HIT Scraper WITH EXPORT': https://greasyfork.org/en/scripts/2002-hit-scraper-with-export
- // use localStorage instead of GM's storage
- 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
- this.GM_getValue=function (key,def) {
- return localStorage[key] || def;
- };
- this.GM_setValue=function (key,value) {
- return localStorage[key]=value;
- };
- this.GM_deleteValue=function (key) {
- return localStorage.removeItem(key);
- };
- }
- // load ignore list
- console.log("blocklist script loaded");
- var ignore_list;
- if ( !GM_getValue("scraper_ignore_list") ){
- GM_setValue("scraper_ignore_list","nothing blocked yet");
- }
- if ( GM_getValue("scraper_ignore_list") ){
- ignore_list = GM_getValue("scraper_ignore_list").split('^');
- console.log(ignore_list);
- }
- // check ignore list for requester name and HIT title
- function ignore_check(r,t){
- var tempList = ignore_list.map(function(item) { return item.toLowerCase(); });
- var foundR = -1;
- var foundT = -1;
- foundR = tempList.indexOf(r.toLowerCase());
- foundT = tempList.indexOf(t.toLowerCase());
- var found = foundR == -1 && foundT == -1;
- return found; // returns false (making !(ignore_check(x,y)) true) if HIT should be blocked, returns true if it shouldn't be blocked
- }
- // identify HITs, requesters, and titles
- var $requester = $('a[href^="/mturk/searchbar?selectedSearchType=hitgroups&requester"]');
- var $title = $('a[class="capsulelink"]');
- 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
- console.log("HIT capsules identified: " + $hitcapsule.length);
- // hide blocked hits
- var blockedcount = 0;
- function hideBlocked(){
- console.log("starting to block, total HITs to check: " + $requester.length);
- blockedcount = 0;
- for (var j = 0; j < $requester.length; j++){
- var requester_name = $requester.eq(j).text().trim();
- var title = $title.eq(j).text().trim();
- console.log("HIT " + (j+1) + " detected. Requester: " + requester_name + ", Title: " + title);
- var hitcapsule = $hitcapsule.eq(j);
- if (!ignore_check(requester_name,title)){ // hide hit if requester name or hit title is in your blocklist
- hitcapsule.hide();
- blockedcount++;
- console.log("blocked HIT " + (j+1) );
- }
- }
- console.log("Total HITs blocked: " + blockedcount);
- }
- $(document).ready(hideBlocked()); // initiate hiding first time when page loads
- // unhide blocked hits
- function showBlocked(){
- console.log("starting to un-hide");
- for (var j = 0; j < $requester.length; j++){
- var hitcapsule = $hitcapsule.eq(j);
- hitcapsule.show();
- }
- }
- // open blocklist editor
- var edit_blocks = document.createElement("span");
- edit_blocks.innerHTML = ' <font color="#9ab8ef">|</font> <a href="#" class="footer_links" id="blocklist_edit_link">Edit Blocklist</a>';
- edit_blocks.onclick = function(){
- console.log("opened blocklist editor");
- var textarea = $("#blocklist_text");
- var text = "";
- for (var i in ignore_list){
- text += ignore_list[i]+"^";
- }
- textarea.text(text.substring(0, text.length - 1));
- $("#blocklist_div").show();
- };
- // show/hide blocked hits
- var showAllBlocked = document.createElement("span");
- showAllBlocked.innerHTML = ' <font color="#9ab8ef">|</font> <a href="#" class="footer_links" id="showblocked">Show ' + blockedcount + ' Blocked</a>';
- showAllBlocked.onclick = function(){
- if ( document.getElementById('showblocked').innerHTML.indexOf("Show") > -1 ) {
- console.log("Un-hiding blocked hits - " + document.getElementById('showblocked').innerHTML );
- showBlocked();
- document.getElementById('showblocked').innerHTML = "Hide " + blockedcount + " Blocked";
- }
- else if ( document.getElementById('showblocked').innerHTML.indexOf("Hide") > -1 ) {
- console.log("Re-hiding blocked hits - " + document.getElementById('showblocked').innerHTML );
- hideBlocked();
- document.getElementById('showblocked').innerHTML = "Show " + blockedcount + " Blocked";
- }
- };
- // add edit and show/hide links to page
- var collapseAll = document.getElementById('collapseall');
- collapseAll.parentNode.insertBefore(showAllBlocked, collapseAll.nextSibling);
- collapseAll.parentNode.insertBefore(edit_blocks, collapseAll.nextSibling);
- // For editing the blocklist
- var blocklistdiv = document.createElement('div');
- var blocklisttextarea = document.createElement('textarea');
- blocklistdiv.style.position = 'fixed';
- blocklistdiv.style.width = '500px';
- blocklistdiv.style.height = '255px';
- blocklistdiv.style.left = '50%';
- blocklistdiv.style.right = '50%';
- blocklistdiv.style.margin = '-250px 0px 0px -250px';
- blocklistdiv.style.top = '300px';
- blocklistdiv.style.padding = '5px';
- blocklistdiv.style.border = '2px';
- blocklistdiv.style.backgroundColor = 'black';
- blocklistdiv.style.color = 'white';
- blocklistdiv.style.zIndex = '100';
- blocklistdiv.setAttribute('id','blocklist_div');
- blocklistdiv.style.display = 'none';
- blocklisttextarea.style.padding = '2px';
- blocklisttextarea.style.width = '500px';
- blocklisttextarea.style.height = '180px';
- blocklisttextarea.title = 'Block list';
- blocklisttextarea.setAttribute('id','blocklist_text');
- 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.)';
- blocklistdiv.style.fontSize = '12px';
- blocklistdiv.appendChild(blocklisttextarea);
- var save_BLbutton = document.createElement('button');
- var cancel_BLbutton = document.createElement('button');
- save_BLbutton.textContent = 'Save';
- save_BLbutton.setAttribute('id', 'save_BLblocklist');
- save_BLbutton.style.height = '18px';
- save_BLbutton.style.width = '100px';
- save_BLbutton.style.fontSize = '10px';
- save_BLbutton.style.paddingLeft = '3px';
- save_BLbutton.style.paddingRight = '3px';
- save_BLbutton.style.backgroundColor = 'white';
- save_BLbutton.style.marginLeft = '5px';
- cancel_BLbutton.textContent = 'Cancel';
- cancel_BLbutton.setAttribute('id', 'cancel_BLblocklist');
- cancel_BLbutton.style.height = '18px';
- cancel_BLbutton.style.width = '100px';
- cancel_BLbutton.style.fontSize = '10px';
- cancel_BLbutton.style.paddingLeft = '3px';
- cancel_BLbutton.style.paddingRight = '3px';
- cancel_BLbutton.style.backgroundColor = 'white';
- cancel_BLbutton.style.marginLeft = '5px';
- blocklistdiv.appendChild(save_BLbutton);
- blocklistdiv.appendChild(cancel_BLbutton);
- save_BLbutton.addEventListener("click", function() {save_BLblocklist();}, false);
- cancel_BLbutton.addEventListener("click", function() {$("#blocklist_div").hide();}, false);
- document.body.insertBefore(blocklistdiv, document.body.firstChild);
- function save_BLblocklist() {
- console.log("Save");
- var textarea = $("#blocklist_text");
- var text = textarea.val();
- var block_list = text.split("^");
- var trimmed_list = [];
- for (var requester in block_list){
- if (block_list[requester].trim().length != 0)
- trimmed_list.push(block_list[requester].toLowerCase().trim());
- }
- console.log(trimmed_list);
- GM_setValue("scraper_ignore_list",trimmed_list.join('^'));
- ignore_list = GM_getValue("scraper_ignore_list").split('^');
- console.log("Save complete: ");
- console.log(ignore_list);
- $("#blocklist_div").hide();
- }