austindh / MTurk Projected Earnings

// ==UserScript==
// @name       MTurk Projected Earnings
// @namespace  http://use.i.E.your.homepage/
// @version    0.2
// @description  enter something useful
// @match      https://www.mturk.com/mturk/statusdetail*
// @copyright  2012+, You
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==

//CSS//
//Showing only paid number
GM_addStyle('.paid {font-size:14px;color:lime;margin-left:5px;}');

//Background fill
GM_addStyle('.background {background-color:darkgreen;padding:4px;border-radius:3px;}');

//Partially paid
GM_addStyle('.partialPaid {color:black;margin-left:5px;}');
GM_addStyle('.paidAmount {font-size:12px;color:lime;margin-left:6px;padding-left:5px;}');
GM_addStyle('.pendingAmount {font-size:12px;color:yellow;margin-left:5px;padding-left:5px;}');
	
	var total = 0;
	var paid = 0;
	var pending = 0;

	var hitsTable = $( "#dailyActivityTable tbody tr" ); //rows containing all hits
	//Loop through hits, totaling
	for ( var i = 1; i < hitsTable.length; i++ ) { //first row is header
        var value = hitsTable.find( ".reward" )[i - 1];
        value = Math.round( parseFloat( $( value ).text().split( "$" )[1] ) * 100 );
        var status = hitsTable.find( ".statusdetailStatusColumnValue" )[i - 1];
        status = $( status ).text();
        
        if ( status === "Paid" ) {
        	paid += value;
        } else if ( status.match( /Pending/ ) ){
        	pending += value;
        }
        
        total += value;
    }

	paid /= 100;
	paid = paid.toFixed( 2 );
	pending /= 100;
	pending = pending.toFixed( 2 );
	total /= 100;
	total = total.toFixed( 2 );

	//Change HTML of top row of table to display the total
	var html = $( ".white_text_14_bold" ).html();
	//html = html.replace("\"","'");
	if ( paid === total) {
        html += "<span class=\"paid background\">$" + total + " Paid</span>";
    } else {
        html += "<span class=\"partialPaid\">$" + total + 
            "</span><span class=\"paidAmount background\">($" + paid + " Paid)</span><span class=\"pendingAmount background\">($" + pending + " Pending)</span>";
    }
	
	$(".white_text_14_bold").html( html );