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.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

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