Greasy Fork

mTurk HITs Accepted on Dashboard

This script is for mTurk. Shows the number of hits you have accepted and lists the first page of them on your dashboard.

当前为 2014-10-20 提交的版本,查看 最新版本

// ==UserScript==
// @name         mTurk HITs Accepted on Dashboard
// @namespace    http://ericfraze.com
// @version      0.2
// @description  This script is for mTurk. Shows the number of hits you have accepted and lists the first page of them on your dashboard.
// @author       Eric Fraze
// @match        https://www.mturk.com/mturk/*
// @grant        none
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
// ==/UserScript==

var hitsAssigned = "N/A (there was an error or something, contact Magnilucent if it happens a lot)";
var hitString = "";
var title = [];
var requester = [];
var pay = [];
var timeLeft = [];
var returnURL = [];
var continueURL = [];

url = window.location.href;
if ( url.indexOf("dashboard") !== -1 ) {
    $.ajax({
        url: "https://www.mturk.com/mturk/myhits",
        dataType: "html",
        success: function(data) {
            if ( $("td:contains('There are currently no HITs assigned to you.')", data).length ) {
                hitsAssigned = 0;
            }else{
                var text = $("td.title_orange_text[style='white-space: nowrap; padding-top: 1ex;']", data).text();
                var regstring = /(\d{1,2})(\sResults)/;
                var reg = new RegExp(regstring);
                var groups = reg.exec(text);
                
                
                hitsAssigned = groups[1];
                
                hitString = '<table class="metrics-table" width="100%">' +
                    '<tbody><tr class="metrics-table-header-row">' +
                        '<th class="metrics-table-first-header">' +
                          'Title' +
                        '</th>' +
                        '<th>' +
                            'Requester' +
                        '</th>' +
                        '<th>' +
                            'Reward' +
                        '</th>' +
                        '<th style="white-space: nowrap;">' +
                            'Time Left' +
                        '</th>' +
                        '<th>' +
                            'Return' +
                        '</th>' +
                    '</tr>';
                
                $('table[width="100%"][height="100%"]', data).each( function(i) {
                    title[i] = $(this).find("a.capsulelink[href='#']").text().trim();
                    requester[i] = $(this).find(".requesterIdentity").text()
                    pay[i] = $(this).find(".reward").text()
                    timeLeft[i] = $(this).find("td[width='25%'] td.capsule_field_text").text().trim();
                    var sign = "odd"
                    if ( ((i + 1)/2) == Math.round((i + 1)/2) )
                        sign = 'even';
                    
                    timeLeft[i] = timeLeft[i].replace(" minutes", "m").replace(" seconds", "s");;
                    
                    returnURL[i] = $(this).find("a[href^='/mturk/return']").attr("href");
                    continueURL[i] = $(this).find("a[href^='/mturk/continue']").attr("href");
                    
                    hitString += '<tr class="' + sign + '">' +
                                    '<td class="metrics-table-first-value"><a href="' + continueURL[i] + '">' + (title[i].length > 60 ? title[i].substring(0, 60 - 3) + '...' : title[i]) + '</a></td>' +
                                    '<td style="white-space: nowrap;"><a href="/mturk/searchbar?searchWords=' + encodeURIComponent(requester[i]) + '">' + (requester[i].length > 15 ? requester[i].substring(0, 15 - 3) + '...' : requester[i]) + '</a></td>' +
                                    '<td>' + pay[i] + '</td>' +
                                    '<td>' + timeLeft[i] + '</td>' +
                        			'<td style="text-align: center;"><a href="' + returnURL[i] + '">Return</a></td>' +
                                 '</tr>';
                });
                
                hitString += '</tbody></table>';
            }
            addHitNumber();
        }
    });
}

$(document).ready(function() {
    if ( $("td:contains('Your HIT Status')").length ) {
    	addHitNumber();
    }
});

function addHitNumber() {
    if ( !$("#HITNumber").length ){
    	$("td:contains('Your HIT Status')").parents("table").before('<table width="760" align="center" cellspacing="0" cellpadding="0"><tbody><tr height="25px"><td width="10" bgcolor="#7fb4cf" style="padding-left: 10px;"></td><td width="100%" bgcolor="#7fb4cf" class="white_text_14_bold"><a href="https://www.mturk.com/mturk/myhits">HITs Assigned to You</a> (<span id="HITNumber">' + hitsAssigned + '</span>)</td><td width="10" align="right" bgcolor="#7fb4cf"></td></tr><tr><td class="container-content" colspan="3"><table class="metrics-table" width="100%"><tbody><tr><td id="HITInfo"></td></tr></tbody></table></td></tr></tbody></table>');
        $("#HITInfo").append(hitString);
    }else{
        $("#HITNumber").text(hitsAssigned);
        $("#HITInfo").empty();
        $("#HITInfo").append(hitString);
    }
}