Hit Timer Fixed

This is an edited version of Hit Timer 0.1 that fixes the compatibility issues with Firefox and adds support for auto-accepted HITs. Tested and working in Firefox 26 and Chrome 32.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name       	Hit Timer Fixed
// @namespace 	http://userscripts.org/users/43629
// @version    	0.1
// @description This is an edited version of Hit Timer 0.1 that fixes the compatibility issues with Firefox and adds support for auto-accepted HITs. Tested and working in Firefox 26 and Chrome 32.
// @match	https://www.mturk.com/mturk/accept*
// @match	https://www.mturk.com/mturk/previewandaccept*
// @match	https://www.mturk.com/mturk/statusdetail*
// @match       https://www.mturk.com/mturk/submit*
// @copyright  	2013+, Ben McMath, Jasmine Branch
// @require 	http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js
// @grant       none
// ==/UserScript==



if($('#theTime').length > 0)
{
    console.log("-=-=-= Found a Timer");
    
        var checker = setInterval(function(){
    	var hitId = document.getElementsByName("hitId")[1].value;
        var theTime = document.getElementById('theTime').textContent;
        if(typeof(Storage)!=="undefined")
        {
        	// Yes! localStorage and sessionStorage support!
	        localStorage.setItem('hitTimer.' + hitId, theTime);
        }
        else
        {
    	    // Sorry! No web storage support..
            console.log("-=-=-= Your browser doesn't support local storage, and therefore we can not track the timing of hits");
            clearInterval(checker);
        }
    }, 1000);
}

// see if we are on the status page
if(document.getElementsByClassName('IKnowYou').length > 0)
{
    setTimeout(loadTimes, 1000);    
}

function loadTimes()
{
	addHeaderColumn();

	var requesterColumns = document.getElementsByClassName('statusdetailRequesterColumnValue');
	
	for (var i = requesterColumns.length - 1; i >= 0; i--) {
			var linkElement = null;
            for(var j = requesterColumns[i].children.length -1; j >= 0; j--)
            {
                if(requesterColumns[i].children[j].tagName = "A")
                {
                    linkElement = requesterColumns[i].children[j];
                    break;
                }
            }
            
            if(typeof linkElement != 'undefined')
            {
                var hitId = linkElement.href.match(/[A-Z0-9]{30}/);
                var timeTaken = getTime(hitId);
                
                addTimeTaken(requesterColumns[i], timeTaken);
            }
	}
}
    
function addHeaderColumn()
{
	var header = document.getElementsByClassName('grayHead');
	var timeColumn = document.createElement('th');
	var timeTitle = document.createTextNode('Estimated Time Taken');
	timeColumn.appendChild(timeTitle);
	header[0].appendChild(timeColumn);
}
    
function getTime(hitId)
{
    var timeTaken = localStorage.getItem('hitTimer.' + hitId);
    return (timeTaken == null) ? '' : timeTaken;
}
    
function addTimeTaken(element, timeTaken)
{
	var timeColumn = document.createElement('td');
	timeColumn.appendChild(document.createTextNode(timeTaken));
	element.parentNode.appendChild(timeColumn);
}