Greasy Fork镜像 is available in English.

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

// ==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.2c
// @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://greasyforks.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;
var blockednames = "";
function hideBlocked(){
    console.log("starting to block, total HITs to check: " + $requester.length);
    blockedcount = 0;
    blockednames = "";
    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.css('outline','red solid thick');
            hitcapsule.hide();
            blockedcount++;
            blockednames += requester_name + ", ";
            console.log("blocked HIT " + (j+1) );
        }
    }
    console.log("Total HITs blocked: " + blockedcount);
    blockednames = blockednames.replace(/,\s*$/, "");  // remove final comma and space
}

$(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 blocklinksDivider = '&nbsp;&nbsp;<font color="#9ab8ef">|</font>&nbsp;&nbsp;';
var edit_blocks = document.createElement("span");
edit_blocks.innerHTML = blocklinksDivider + '<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 = blocklinksDivider + '<a href="#" class="footer_links" id="showblocked" title="' + blockednames + '">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 regular search results pages
if ( document.location.href.indexOf('?last_hits_previewed') < 0 ) {
    var collapseAll = document.getElementById('collapseall');
    collapseAll.parentNode.insertBefore(showAllBlocked, collapseAll.nextSibling);
    collapseAll.parentNode.insertBefore(edit_blocks, collapseAll.nextSibling);
}
else {  // add edit and show/hide links to last_hits_previewed page
    edit_blocks.innerHTML = edit_blocks.innerHTML.replace(blocklinksDivider, '');
    $("h1:contains('Last HITs Previewed')").eq(0).after(edit_blocks, showAllBlocked, "<br><br>");
}


// 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();
}
长期地址
遇到问题?请前往 GitHub 提 Issues。