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.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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);
}