JR Mturk Panda Crazy Queue Helper

A script add on for Panda Crazy for displaying queue and sorting queue after submitting hits.

当前为 2017-11-06 提交的版本,查看 最新版本

// ==UserScript==
// @name        JR Mturk Panda Crazy Queue Helper
// @version     0.3.5
// @namespace   https://greasyfork.org/users/6406
// @description A script add on for Panda Crazy for displaying queue and sorting queue after submitting hits.
// @include     http*://*mturk.com/mturk/myhits*
// @include		http*://*mturk.com/mturk/findhits*
// @include		http*://*mturk.com/mturk/sorthits*
// @include		http*://*mturk.com/mturk/sortmyhits*
// @include		http*://*mturk.com/mturk/viewhits*
// @include     http*://*mturk.com/mturk/continue*
// @include     http*://*mturk.com/mturk/accept*
// @include     http*://*mturk.com/mturk/previewandaccept*
// @include     http*://*mturk.com/mturk/submit
// @include     http*://*mturk.com/mturk/return*
// @include		http*://*mturk.com/mturk/*searchbar*
// @include     http*://*mturk.com/mturk/return?requesterId=*
// @include     http*://*mturk.com/mturk/preview?*&prevsubmithitId=*
// @include     http*://www.mturk.com/mturk/externalSubmit
// @include     http*://worker.mturk.com/tasks*
// @include     http*://worker.mturk.com/projects*
// @include     http*://worker.mturk.com/
// @exclude     http*://*mturk.com/mturk/findhits?*hit_scraper*
// @require     http://code.jquery.com/jquery-2.1.4.min.js
// @grant 		GM_xmlhttpRequest
// @grant       GM_getValue
// @grant       GM_setValue
// ==/UserScript==

var gScriptVersion="0.3.5", gQueueHelperFormat2 = true;
var gScriptName="pandacrazy";
var gLocation=window.location.href, gPrevHit="", gPrevTitle="";
var gPandaCrazyLives=false, gHitExternalNextLink="", gHitExternalNextAcceptLink="", gTitle="", gNewSite=false;
var gPandaCrazyVersion=-1, gHitReturnLink="", gThisJob=null, gNoHits=false, gButtonSet=false;
var gQueueData=null, gPE=0, gTabTextMode=0, gTabTextTimer=0, gOriginalTitle=document.title, gCurrentPostion = 0, gQueueNextHit=null;
var gSubmitHitID="", gReturnedHitID=""; // previous hitID submitted or returned just to be sure it doesn't get redone.
var gCorrectVersion=false, gFirstChange=false, gQueueSessOptions=null, gSubmitButton=null, gHitId=null, gIdNum=-1, gTabHitIds={};
var gThisTarget=(new Date().getTime()) + "_JRID"; // target ID from the time to distinguish different scripts and tabs.
var gThisId=-1; // ID number to represent the id in the Panda Crazy external data number ID just for separating messages.
var gQueueSessOptionsDef={"nextPosition":"--","nextIsLast":false,"nextIsSame":false,"tabNum":-1};
var gQueueLocalOptionsDef={"displayTabTitleQ":true,"displayTabTitleTime":true,"displayTabTitleName":true,"displayTabTitleToggle":false,"toggleTime":4000};
var gJobDataDefault={"requesterName":"","requesterId":"","groupId":"","pay":"","title":"","duration":"0","hitsAvailable":0,"timeLeft":"","totalSeconds":0,"hitId":"","qual":"",
		"continueURL":"","returnURL":"","durationParsed":{},"jobNumber":"-1","friendlyRName":"","friendlyTitle":"","assignedOn":"","description":"","keywords":"","timeData":{}};

function speakThisNow(thisText) {
    if('speechSynthesis' in window){
        var speech = new SpeechSynthesisUtterance(thisText);
        speech.lang = 'en-US';
        window.speechSynthesis.speak(speech);
    }
}
function formatAMPM(theFormat,theDate,theTimeZone) {
    var d = (theDate) ? theDate : new Date();
    if (theTimeZone == "mturk") {
        var mturkTZOffset = -8, today = new Date(); if (today.dst()) mturkTZOffset++;
        var utc = d.getTime() + (d.getTimezoneOffset() * 60000), MturkTime = utc + (3600000 * mturkTZOffset);
        d = new Date(MturkTime);
    }
    var minutes = d.getMinutes().toString().length == 1 ? '0'+d.getMinutes() : d.getMinutes(),
        hours = d.getHours(), ampm = hours >= 12 ? 'pm' : 'am',
        months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], days = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
	hours = (hours>= 12) ? (hours-12) : hours;
	hours = (hours.toString().length == 1) ? '0'+hours : hours;
    if (theFormat=="short") return ('0' + (d.getMonth()+1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2) + '-' + d.getFullYear() + '(' + hours + ':' + minutes + ampm + ')';
    else if (theFormat=="dayandtime") return days[d.getDay()] + ' ' + hours + ':' + minutes + ampm;
    else if (theFormat=="onlydate") return ('0' + (d.getMonth()+1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2) + '-' + d.getFullYear();
    else return days[d.getDay()]+' '+months[d.getMonth()]+' '+d.getDate()+' '+d.getFullYear()+' '+hours+':'+minutes+ampm;
}
function formatTimeZone(theFormat,theDate,theTimeZone) { return formatAMPM(theFormat,theDate,theTimeZone); }
function getTimeLeft(theTime) {
    if (theTime!==null && theTime!=="") {
        var tempArray = (theTime.indexOf("second") != -1) ? theTime.split("second")[0].trim().split(" ") : null;
		var seconds = (tempArray) ? parseInt(tempArray[tempArray.length-1]) : 0;
		tempArray = (theTime.indexOf("minute") != -1) ? theTime.split("minute")[0].trim().split(" ") : null;
		var minutes = (tempArray) ? parseInt(tempArray[tempArray.length-1]) : 0;
		tempArray = (theTime.indexOf("hour") != -1) ? theTime.split("hour")[0].trim().split(" ") : null;
		var hours = (tempArray) ? parseInt(tempArray[tempArray.length-1]) : 0;
		tempArray = (theTime.indexOf("day") != -1) ? theTime.split("day")[0].trim().split(" ") : null;
		var days = (tempArray) ? parseInt(tempArray[tempArray.length-1]) : 0;
		tempArray = (theTime.indexOf("week") != -1) ? theTime.split("week")[0].trim().split(" ") : null;
		var weeks = (tempArray) ? parseInt(tempArray[tempArray.length-1]) : 0;
		return( {"weeks":weeks,"days":days,"hours":hours,"minutes":minutes,"seconds":seconds} );
    } else return null;
}
function formatTimeLeft(resetNow,thisDigit,timeString,lastDigit) {
	formatTimeLeft.timeFill = formatTimeLeft.timeFill || 0;
	if (resetNow) formatTimeLeft.timeFill = 0;
	var missingDigit = (lastDigit!="0" && thisDigit=="0") ? true : false;
	if (( thisDigit!="0" || missingDigit) && formatTimeLeft.timeFill<2) {
		formatTimeLeft.timeFill++;
		if (missingDigit) { return "00 " + timeString + "s"; }
		else {
			var addZero = (thisDigit<10) ? ((formatTimeLeft.timeFill==1) ? false : true) : false, plural = (thisDigit==1) ? false : true;
			return ((addZero) ? "0" : "") + thisDigit + " " + ((plural) ? (timeString+"s") : timeString) + " ";
		}
	} else return "";
}
function convertToTimeString(timeData) {
	var returnString = "";
	returnString += formatTimeLeft(true,timeData.weeks,"week","0"); returnString += formatTimeLeft(false,timeData.days,"day",timeData.weeks);
	returnString += formatTimeLeft(false,timeData.hours,"hour",timeData.days); returnString += formatTimeLeft(false,timeData.minutes,"minute",timeData.hours);
	returnString += formatTimeLeft(false,timeData.seconds,"second",timeData.minutes);
	return returnString.trim();
}
function convertTimeToSeconds(timeData) {
	var totalSeconds = timeData.seconds + ((timeData.minutes) ? (timeData.minutes*60) : 0) + ((timeData.hours) ? (timeData.hours*3600) : 0) +
			((timeData.days) ? (timeData.days*86400) : 0) + ((timeData.weeks) ? (timeData.weeks*604800) : 0);
	return totalSeconds;
}
function convertSecondsToTimeData(seconds) {
	var timeData = {};
	timeData.weeks = Math.floor(seconds/604800); seconds = seconds - (timeData.weeks*604800);
	timeData.days = Math.floor(seconds/86400); seconds = seconds - (timeData.days*86400);
	timeData.hours = Math.floor(seconds/3600); seconds = seconds - (timeData.hours*3600);
	timeData.minutes = Math.floor(seconds/60); seconds = seconds - (timeData.minutes*60);
	timeData.seconds = seconds;
	return timeData;
}
function continueLink(theHitId) { return "https://www.mturk.com/mturk/continue?hitId=" + theHitId; }
function returnLink(theHitId) { return "https://www.mturk.com/mturk/return?hitId=" + theHitId + "&inPipeline=false"; }
function convertToSeconds(milliseconds,fixed) { fixed = fixed || 2; var seconds = parseFloat((milliseconds/1000.0 * 100) / 100).toFixed(fixed) + ""; return seconds.replace(/\.0*$/,""); }
function convertToMilliseconds(seconds) { if (seconds) return seconds*1000 + ""; else return "0"; }
function createDiv(theHtml) { var inner = (theHtml) ? theHtml : ""; return $('<div>').html(inner); }
function createSpan(theHtml) { var inner = (theHtml) ? theHtml : ""; return $('<span>').html(inner); }
function createButton(theText) { var inner = (theText) ? theText : ""; return $('<button>').html(inner); }
function createSelect(theId,theOptions) {
	var theSelect = $('<select>').attr({"id":theId});
	for (var i=0,len=theOptions.length; i<len; i++) { theSelect.append("<option value='" + theOptions[i] + "'>" + theOptions[i] + "</option>"); }
	return theSelect;
}
function createSelectNumbers(theId,first,min,max) {
	var buildArray = [first];
	for (var i=min; i<=max; i++) { buildArray.push(i); }
	return createSelect(theId,buildArray);
}
function parseVersionString (str) {
    var x = str.split('.');
    var maj = parseInt(x[0]) || 0; var min = parseInt(x[1]) || 0; var pat = parseInt(x[2]) || 0;
    return {"major": maj, "minor": min, "patch": pat};
}
(function($){ $.fn.disableSelection = function() { return this.attr('unselectable', 'on').css('user-select', 'none').on('selectstart', false); }; })(jQuery);
function saveSessionData() {
	sessionStorage.setItem("JR_PC_QueueHelper",JSON.stringify(gQueueSessOptions));
}
function loadSessionData() {
	gQueueSessOptions = JSON.parse(sessionStorage.getItem('JR_PC_QueueHelper'));
	gQueueNextHit = JSON.parse(sessionStorage.getItem('JR_queueOrder_hitID',null));
	gPrevHit = sessionStorage.getItem('JR_PC_QPrevHitId'); gPrevTitle = sessionStorage.getItem('JR_PC_QPrevTitle');
	gReturnedHitID = sessionStorage.getItem("JR_PC_QReturnedHitId") || "";
    sessionStorage.removeItem('JR_PC_QPrevHitId'); sessionStorage.removeItem('JR_PC_QPrevTitle'); sessionStorage.removeItem('JR_PC_QReturnedHitId');
	if (!gQueueSessOptions) {
		sessionStorage.setItem("JR_PC_QueueHelper",JSON.stringify(gQueueSessOptionsDef));
		gQueueSessOptions = JSON.parse(sessionStorage.getItem('JR_PC_QueueHelper'));
	}
}
function checkVersion(greaterThanVersion,newVersion) { // Check if newVersion is GREATER than the greaterThanVersion
	var greaterThanVersionObj = parseVersionString(greaterThanVersion), newVersionObj = parseVersionString(newVersion);
	if (newVersionObj.major > greaterThanVersionObj.major ) return true;
	else if (greaterThanVersionObj.major==newVersionObj.major) {
		if (newVersionObj.minor > greaterThanVersionObj.minor) return true;
		else if (greaterThanVersionObj.minor==newVersionObj.minor && newVersionObj.patch > greaterThanVersionObj.patch) return true;
	}
	return false;
}
function checkMode() {
    var checkModeVar = "";
	if (gLocation.indexOf("JRPC=nexthit") != -1) checkModeVar = "queuePageNextStart";
	else if (gLocation.indexOf("JRPC=gohit") != -1 ) checkModeVar = "goToNum";
	else if (gLocation.indexOf("JRPC=lasthit") != -1 ) checkModeVar = "goLastHit";
	else if (gLocation.indexOf("JRPC=monitornext") != -1 ) checkModeVar = "monitorQueue";
	else if (gLocation.indexOf("mturk/sortmyhits?") != -1 || gLocation.indexOf("mturk/myhits") != -1) checkModeVar = "queuePageStart";
	else if (gLocation.indexOf("mturk/continue") != -1) checkModeVar = "hitPage";
	else if (gLocation.indexOf("mturk/accept") != -1 && gLocation.indexOf("&prevHitSubmitted=") != -1) checkModeVar = "accepted";
	else if (gLocation.indexOf("mturk/previewandaccept") != -1) checkModeVar = "accepted";
	else if (gLocation.indexOf("mturk/preview") != -1) checkModeVar = "previewPage";
	else if (gLocation.indexOf("mturk/submit") != -1) checkModeVar = "submitPage";
	else if (gLocation.indexOf("mturk/return") != -1) checkModeVar = "returnPage";
    if (checkModeVar!=="") return checkModeVar; else return null;
}
function checkNewMode() {
    var checkModeVar = "";
	if (gLocation.match(/mturk\.com\/projects\/.*\/tasks\/.*assignment_id.*$/) !== null) { checkModeVar = "hitPage"; } // found Hit page.
	else if (gLocation.match(/\/tasks.*JRPC\=nexthit.*/) !== null) { checkModeVar = "queuePageNextStart"; } // wants to go to next hit in queue.
	else if (gLocation.match(/\/tasks.*JRPC\=gohit[0-9]*/) !== null) { checkModeVar = "goToNum"; } // wants to go to a specific nummber in queue.
	else if (gLocation.match(/\/tasks.*JRPC\=lasthit.*/) !== null) { checkModeVar = "goLastHit"; } // wants to go to last hit in queue.
	else if (gLocation.match(/\/tasks.*JRPC\=monitornext.*/) !== null) { checkModeVar = "monitorQueue"; } // monitor queue data and go to first one accepted.
    if (checkModeVar!=="") return checkModeVar; else return null;
}
function getTimeLeft(theTime) {
    if (theTime) {
        var tempArray = (theTime.indexOf("second") != -1) ? theTime.split("second")[0].trim().split(" ") : null;
		var seconds = (tempArray) ? tempArray[tempArray.length-1] : "0";
		tempArray = (theTime.indexOf("minute") != -1) ? theTime.split("minute")[0].trim().split(" ") : null;
		var minutes = (tempArray) ? tempArray[tempArray.length-1] : "0";
		tempArray = (theTime.indexOf("hour") != -1) ? theTime.split("hour")[0].trim().split(" ") : null;
		var hours = (tempArray) ? tempArray[tempArray.length-1] : "0";
		tempArray = (theTime.indexOf("day") != -1) ? theTime.split("day")[0].trim().split(" ") : null;
		var days = (tempArray) ? tempArray[tempArray.length-1] : "0";
		tempArray = (theTime.indexOf("week") != -1) ? theTime.split("week")[0].trim().split(" ") : null;
		var weeks = (tempArray) ? tempArray[tempArray.length-1] : "0";
		return( {"weeks":weeks,"days":days,"hours":hours,"minutes":minutes,"seconds":seconds} );
    } else return null;
}
function clearOldTabMessages() {
	var storageKeys = Object.keys(localStorage);
	for (i = 0; i < storageKeys.length; i++)   {
		if (storageKeys[i].substring(0,14) == 'JR_message_TAB' &&  storageKeys[i].substr(storageKeys[i].length - gScriptName.length) == gScriptName) {
			localStorage.removeItem(storageKeys[i]);
		}
	}
}
function createMessageData(command,data,target,idNum,tabNum) { return {"time":(new Date().getTime()),"command":command,"data":data,"theTarget":target,"idNum":idNum,"tabNum":tabNum}; }
function createHitData(hitId,target,idNum,prevId) { return {"hitId":hitId,"idNum":idNum,"prevId":prevId}; }
function sendCommandMessage(data) { localStorage.setItem("JR_message_" + gScriptName, JSON.stringify(data)); }

function sendMessageData(command,theData) {
	var messageData = createMessageData(command,theData);
	sendCommandMessage(messageData);
}
function sendPingMessage(target) { localStorage.setItem("JR_message_ping_" + gScriptName, JSON.stringify(createMessageData("areYouThere",
	{"version":gScriptVersion,"extName":"QueueHelper"},target,null,null))); }
function sendPongMessage(target,idNum) { localStorage.setItem("JR_message_pong_" + gScriptName, JSON.stringify(createMessageData("iAmHere",null,target,idNum,null))); }
function sendQueuePageMessage(target,idNum) { localStorage.setItem("JR_message_" + gScriptName, JSON.stringify(createMessageData("getQueueData",null,target,idNum,null))); }
function setQueueHitMessage(target,idNum,hitId,prevId) { sessionStorage.setItem("JR_queueOrder_hitID", JSON.stringify(createHitData(hitId,target,idNum,prevId))); }
function sendSubmittedMessage(target,thisHitID,idNum) { localStorage.setItem("JR_message_" + gScriptName,
		JSON.stringify(createMessageData("submitted",{"hitId":thisHitID},target,idNum,null))); }
function sendReturnedMessage(target,thisHitID,idNum) { localStorage.setItem("JR_message_" + gScriptName,
		JSON.stringify(createMessageData("returned",{"hitId":thisHitID},target,idNum,null))); }
function sendAcceptedHitMessage(target,thisJobData,idNum) { localStorage.setItem("JR_message_" + gScriptName,
		JSON.stringify(createMessageData("acceptedhit",{"jobData":thisJobData},target,idNum,null))); }
function sendDoingHitMessage(tabNum,target,thisHitID,mode,idNum) { localStorage.setItem("JR_message_" + mode + "_" + tabNum + "_" + gScriptName,
		JSON.stringify(createMessageData("doinghit",{"hitId":thisHitID},target,idNum,tabNum))); }
function setSessionData() {
	if ($("#JRPCQAdvSel").length) gQueueSessOptions.nextPosition = $("#JRPCQAdvSel").val();
	if ($("#JRPCQEasySel").val()=="Last") gQueueSessOptions.nextIsLast = true; else gQueueSessOptions.nextIsLast = false;
	if ($("#JRPCQSameSel").val()=="No") gQueueSessOptions.nextIsSame = false; else gQueueSessOptions.nextIsSame = true;
	saveSessionData();
}
function setupOptionsMenu() {
	var insideContent = $("#JR_QueueOptionsMenu");
	createDiv("Queue Options Window").css({"font-size":"22px","text-align":"center","margin":"8px 0"}).appendTo(insideContent);
	var optionsArea = createDiv("").css({"font-size":"14px","text-align":"left","padding":"0 10px","margin-top":"20px"}).appendTo(insideContent);
	createDiv(createSpan("Go to the ").append(createSelect("JRPCQEasySel",["First","Last","--"])).append(createSpan(" hit in the queue."))).appendTo(optionsArea);
	createDiv(createSpan("Go to the next hit at position ").css({}).append(createSelectNumbers("JRPCQAdvSel","--",1,24)).append(createSpan(" in the queue."))).appendTo(optionsArea);
	createDiv(createSpan("Go to the next hit with same description? ").css({}).append(createSelect("JRPCQSameSel",["No","Yes"]))).appendTo(optionsArea);
	createButton("OK").css({"margin-top":"40px","margin-left":"10px"}).click(function() { toggleOptionsMenu(); }).appendTo(optionsArea);
	$("#JRPCQEasySel").val((gQueueSessOptions.nextPosition!="--") ? "--" : ((gQueueSessOptions.nextIsLast) ? "Last" : "First"));
	$("#JRPCQAdvSel").val(gQueueSessOptions.nextPosition);
	$("#JRPCQSameSel").val((gQueueSessOptions.nextIsSame) ? "Yes" : "No");
	$("#JRPCQEasySel").change(function() { if ($(this).val()!="--") $("#JRPCQAdvSel").val("--"); else $("#JRPCQAdvSel").val("1"); setSessionData(); });
	$("#JRPCQAdvSel").change(function() { if ($(this).val()!="--") $("#JRPCQEasySel").val("--"); else $("#JRPCQEasySel").val("First"); setSessionData(); });
	$("#JRPCQSameSel").change(function() { setSessionData(); });
}
function toggleOptionsMenu() {
	toggleOptionsMenu.display = toggleOptionsMenu.display || false;
	toggleOptionsMenu.display = !toggleOptionsMenu.display;
	if (toggleOptionsMenu.display) $("#JR_QueueOptionsMenu").show();
	else $("#JR_QueueOptionsMenu").hide();
}
function requestUrl(theUrl, theNumber, theFunction, errorFunction, data1, data2, theResponseType) {
    theResponseType = theResponseType || "";
    GM_xmlhttpRequest({
        method: "GET",
        url: theUrl,
        responseType: theResponseType,
        onload: function(response) { if (typeof theFunction == 'function') theFunction(response,theNumber,data1,data2); },
        onerror: function(response) { errorRequest(response,theNumber); }
    });
}
function grabJobData(index) {
	var jobData = jQuery.extend(true, {}, gJobDataDefault), titleElement = $("#capsule" + index + "-0"), timeLeft = null, keywordsArray=[];
	if (titleElement.length) {
		jobData.title = $(titleElement).text().trim();
		var returnLinkURL = $(titleElement).closest("tr").find("a:contains('Return this HIT'):first");
		jobData.returnURL = (returnLinkURL.length) ? "https://www.mturk.com" + $(returnLinkURL).attr("href") : "";
		var continueLinkURL = $(titleElement).closest("tr").find("a:contains('Continue work on this HIT'):first");
		jobData.continueURL = (continueLinkURL.length) ? "https://www.mturk.com" + $(continueLinkURL).attr("href") : "";
		jobData.hitId = (jobData.continueURL!=="") ? jobData.continueURL.split("hitId=")[1] : "";
		var requesterElement = $(".requesterIdentity:first");
		jobData.requesterName = (requesterElement.length) ? $(requesterElement).text().trim() : "";
		var contactRequesterUrl = $("#capsule" + index + "target").find("a:contains('Contact the Requester of this HIT'):first");
		jobData.requesterId = (contactRequesterUrl.length) ? $(contactRequesterUrl).attr("href").split("requesterId=")[1].split("&")[0] : "";
		var durationToComplete = $("#duration_to_complete\\.tooltip--" + index);
		jobData.duration = (durationToComplete.length) ? $(durationToComplete).closest("tr").find(".capsule_field_text").text().trim() : "";
		jobData.durationParsed = getTimeLeft(jobData.duration);
		var description = $("#description\\.tooltip--" + index);
		jobData.description = (description.length) ? $(description).closest("tr").find(".capsule_field_text").text().trim() : "";
		var rewardElement = $("#reward\\.tooltip--" + index);
		jobData.pay = (rewardElement.length) ? $(rewardElement).closest("tr").find(".reward").text().replace("$","").trim() : "";
	} else {
		var capsulelinkElement = $("form[name='hitForm'] .capsulelink_bold");
		var tableInfo = $(capsulelinkElement).closest("table").closest("table");
		jobData.groupId = (gLocation.indexOf("groupId=") != -1) ? gLocation.split("groupId=")[1].split("&")[0] : "";
		jobData.title = $(capsulelinkElement).find("div").text().trim();
		jobData.hitId = $("input[name='hitId']").eq(0).val();
		jobData.continueURL = (jobData.hitId!=="") ? continueLink(jobData.hitId) : "";
		jobData.returnURL = (jobData.hitId!=="") ? returnLink(jobData.hitId) : "";
		jobData.requesterId = ($("input[name='requesterId']:first").val()) ? $("input[name='requesterId']:first").attr("value") : "";
		jobData.requesterName = $("#requester\\.tooltip").closest("tr").find(".capsule_field_text:first").text().trim();
        timeLeft = $("a#time_left\\.tooltip"); jobData.duration = (timeLeft.length) ? timeLeft.parent().next().html().trim() : "";
		jobData.duration = $("#time_left\\.tooltip").closest("td").next().text().trim();
		jobData.durationParsed = getTimeLeft(jobData.duration); jobData.timeData = jobData.durationParsed; jobData.timeLeft = convertToTimeString(jobData.durationParsed);
		jobData.totalSeconds = convertTimeToSeconds(jobData.timeData);
		jobData.hitsAvailable = $("#number_of_hits\\.tooltip").closest("td").next().text().trim();
		jobData.pay = $("#reward\\.tooltip").closest("td").next().text().replace("$","").replace(" per HIT","").trim();
	}
	return jobData;
}
function inOtherTabs(hitId) { var foundIt=false; $.each(gTabHitIds, function(key,value) { if (value==hitId && key!=gQueueSessOptions.tabNum) foundIt=true; }); return foundIt; }
function doSortResultsTable(sortresultsForm) {
	var sortResultsTable = $(sortresultsForm).next("table"), jobDatas = [];
	$(sortResultsTable).find("> tbody > tr").each(function(i, row) {
		var returnData = grabJobData(i);
		if (!inOtherTabs(returnData.hitId)) jobDatas.push(returnData);
	});
	return jobDatas;
}
function firstOrLast(i) { return (gQueueSessOptions.nextIsLast) ? (i>0) : (i<gQueueData.length-1); }
function letsFindNext() {
}
function findNextHitQueue(currentHitID,sameDescription,leaveCurrent) {
	if (!gQueueData || currentHitID === "") return null;
    sameDescription = sameDescription || "";
	var i=-1, skip=false, targetHit=null, nextPosition = (gQueueSessOptions.nextPosition=="--") ? -2 : parseInt(gQueueSessOptions.nextPosition);
	var getLast = (gQueueSessOptions.nextIsLast) ? true : ((nextPosition>gQueueData.length-1) ? true : false);
    if (leaveCurrent) nextPosition--;
	for (j=0,len=gQueueData.length;j<len;j++) {
		if (gQueueData[j].hitId==currentHitID) gCurrentPostion = j+1; // find the currenthit position
		if (!targetHit || getLast) { // if targethit not found or looking for last hit then keep on looking for target hit!
			if ( (leaveCurrent || gQueueData[j].hitId!=currentHitID) && gQueueData[j].hitId!=gSubmitHitID && gQueueData[j].hitId!=gReturnedHitID && !inOtherTabs(gQueueData[j].hitId)) {
				if (sameDescription==="" || gQueueData[j].title==sameDescription) targetHit = gQueueData[j];
			}
			if (!getLast && nextPosition>0 && j<nextPosition) targetHit=null;
		}
	}
	if (!targetHit && gQueueData.length>1 && getLast) targetHit = gQueueData[gQueueData.length-1];
	return targetHit;
}
function doYourQueue() {
	if (!gPandaCrazyLives) {
		requestUrl("https://www.mturk.com/mturk/sortmyhits?searchSpec=HITSearch%23T%231%2310%23-1%23T%23!Status!0!rO0ABXQACEFzc2lnbmVk!%23!Deadline!0!%23!&selectedSearchType=hitgroups&searchWords=&sortType=Deadline%3A0&pageSize=25",1,function(theResult,theNumber,data1,data2) {
		},function() { errorRequest(); } );
	}
}
function queuePageStart() {
	var sortresultsForm = $("#sortresults_form"), hitsText = $(sortresultsForm).prev(), lastTables = $(sortresultsForm).next().next();
	$(hitsText).find(".title_orange_text_bold").append(createSpan("PC Enhanced Mode").css({"font-size":"11px","padding":"1px 2px","background-color":"#FFE4C4","color":"black"}));
	var displayHits = $(sortresultsForm).next(), afterThis = $("#subtabs_and_searchbar");
	theMainContainer = createDiv().attr({"id":"JRMQContainer"}).insertAfter(afterThis);
	createDiv().attr({"id":"JRNormalQueue"}).appendTo(theMainContainer);
	$("#JRNormalQueue").append($(hitsText)); $("#JRNormalQueue").append($(sortresultsForm)); $("#JRNormalQueue").append($(displayHits));
	createDiv().attr({"id":"JREnhancedQueue1"}).appendTo(theMainContainer); createDiv().attr({"id":"JREnhancedQueue"}).appendTo(theMainContainer);
	if (gScriptMode=="queuePageNextStart" || gScriptMode=="goLastHit" || gScriptMode=="goToNum") {
		$("body").children("div,table").css("opacity","0.1");
		setTimeout(function() {
			var hitData = doSortResultsTable($("#sortresults_form"));
			if (hitData.length>0) {
				var positionNum = 0;
				if (gScriptMode=="goLastHit") {
					gQueueSessOptions.nextPosition="--"; gQueueSessOptions.nextIsLast=true; gQueueSessOptions.nextIsSame=false; // reset options to look for last hit.
					positionNum = hitData.length-1;
				}
				if (gScriptMode=="goToNum") {
					var positionNumFirst = gLocation.split("JRPC=gohit")[1]; // find the go hit command to split it from the number.
					if (positionNumFirst) positionNum = positionNumFirst.match(/\d+/)[0]; // match the first number found and set variable to it.
					if (positionNum<1 && positionNum>25) positionNum=0;
					else {
						gQueueSessOptions.nextPosition = positionNum; gQueueSessOptions.nextIsLast=false; gQueueSessOptions.nextIsSame=false; // reset options to look for next position.
						positionNum=positionNum-1;
					}
				}
				setTimeout(function() { console.log(positionNum); window.location.replace(hitData[positionNum].continueURL); },(!gPandaCrazyLives) ? 700 : 1);
			} else {
				$("body").children("div,table").css("opacity","1");
				gScriptMode = "queuePage";
			}
		},(!gPandaCrazyLives) ? 1 : 1000);
		if (gScriptMode=="queuePageNextStart") gScriptMode = "queuePageNext";
	} else gScriptMode = "queuePage";
}
function queuePageNewStart() {
	var jobData = jQuery.extend(true, {}, gJobDataDefault);
    var queueDataDiv = $(".task-queue-header:first").next().find("div"); // look for the queue header div and put in variable.
    var reactInfoList = queueDataDiv[1].dataset.reactProps; // grab the list of hits in queue
	if (reactInfoList) { // was list found?
		queueData = JSON.parse(reactInfoList).bodyData; // convert the list of hits into an array of objects.
        var foundNextOne = null; // initialize variable to represent not found so stay on current hit.
	    for (j=0,len=queueData.length;j<len && !foundNextOne;j++) { // go through array of hits one by one.
            if (!inOtherTabs(queueData[j].assignment_id)) foundNextOne=queueData[j]; // if not in other tabs then set up variable to next hit.
        }
        if (foundNextOne) { // was next hit found and not current hit?
            setTimeout(function() { window.location.replace("https://worker.mturk.com" + foundNextOne.task_url.replace("&ref=w_pl_prvw","&from_queue=true")); },600);
        } else $("body").children("div,table").css("opacity","1"); // next hit not found or it's the current hit so just undim.
	}
}
function setNextHit() {
	if (gSubmitButton && gSubmitButton.length===0) return;
	var targetHit = findNextHitQueue(gHitId, (gQueueSessOptions.nextIsSame) ? gTitle : "",false);
	if (!targetHit && gQueueSessOptions.nextIsSame) targetHit = findNextHitQueue(gHitId, "",false);
	if (targetHit) {
		var realHitId = $("input[name='hitId']").eq(0).val();
		if (gHitExternalNextLink) $(gHitExternalNextLink).attr("href", targetHit.continueURL + "&prevsubmithitId=" + gHitId);
		var theReturnLinkHref = "https://www.mturk.com/mturk/return?hitId=" + realHitId + "&hitNextId=" + targetHit.hitId + "&inPipeline=false";
		setQueueHitMessage(gThisTarget,gIdNum,targetHit.hitId,gHitId);
		if (gHitReturnLink.length) $(gHitReturnLink).attr("href", theReturnLinkHref);
	} else {
		if (gHitExternalNextLink && gScriptMode!="accepted") {
			var theNextLinkHref = "/mturk/myhits?JRPC=nexthit";
			if (theNextLinkHref.indexOf("&prevsubmithitId=") == -1) theNextLinkHref = theNextLinkHref + "&prevsubmithitId=" + gHitId;
			$(gHitExternalNextLink).attr('href', theNextLinkHref );
		}
		if (gHitExternalNextAcceptLink && $(gHitExternalNextAcceptLink).attr("href").indexOf("&prevsubmithitId=") == -1) {
			$(gHitExternalNextAcceptLink).attr("href", gHitExternalNextAcceptLink.attr("href") + "&prevsubmithitId=" + gHitId);
		}
	}
}
function mainListener(e) {
	var returnedStorage = JSON.parse(e.newValue), messageSender=null;
	if (!returnedStorage) return;
	if (!gPandaCrazyLives) {
		if ( e.key.substring(0,16) == 'JR_message_pong_' &&  e.key.substr(e.key.length - gScriptName.length) == gScriptName && // Receiving correct message from Panda Crazy
				returnedStorage && returnedStorage.theTarget == gThisTarget) { // Receiving as a targeted message for first message from Panda Crazy
			gPandaCrazyLives = true; // We now know Panda Crazy is running.
			gPandaCrazyVersion = returnedStorage.version; gIdNum = returnedStorage.idNum;
			gQueueSessOptions.tabNum = (gQueueSessOptions.tabNum!=-1) ? gQueueSessOptions.tabNum : gIdNum;
			saveSessionData();
			gTabHitIds[gQueueSessOptions.tabNum] = gHitId;
			gCorrectVersion = checkVersion("0.3.7",gPandaCrazyVersion); gFirstChange = checkVersion("0.4.9",gPandaCrazyVersion);
			if (gScriptMode=="queuePageStart" || gScriptMode=="queuePageNextStart" || gScriptMode=="hitPage" || gScriptMode=="previewPage") sendQueuePageMessage(gThisTarget,gIdNum);
		}
	} else if (gHitId!=="" && e.key.substring(0,13) == "JR_message_D_") {
		messageSender = returnedStorage.tabNum;
		if (messageSender && messageSender!=-1) delete gTabHitIds[messageSender];
		setNextHit();
	} else if (gHitId!=="" && e.key.substring(0,13) == "JR_message_S_") {
		messageSender = returnedStorage.tabNum;
		gTabHitIds[messageSender] = returnedStorage.data.hitId;
		sendDoingHitMessage(gQueueSessOptions.tabNum,gThisTarget,gHitId,"R",gIdNum);
		setNextHit();
	} else if (gHitId!=="" && e.key.substring(0,13) == "JR_message_SD_") {
		sendDoingHitMessage(gQueueSessOptions.tabNum,gThisTarget,gHitId,"TAB",gIdNum);
	} else if (gHitId!=="" && (e.key.substring(0,13) == "JR_message_R_" || e.key.substring(0,15) == "JR_message_TAB_") ) {
		messageSender = returnedStorage.tabNum;
		gTabHitIds[messageSender] = returnedStorage.data.hitId;
		setNextHit();
	} else if (gCorrectVersion && returnedStorage && returnedStorage.data) { // Panda Crazy is up and running with correct version.
		if (e.key.substring(0,11) == 'JR_message_' &&  e.key.substr(e.key.length - gScriptName.length) == gScriptName && // Receiving correct message from Panda Crazy
				(returnedStorage.theTarget == gThisTarget || returnedStorage.theTarget===null)) { // Receiving as a targeted message or a ping message
			if (returnedStorage.data.queue) { gQueueData = returnedStorage.data.queue; sendDoingHitMessage(gQueueSessOptions.tabNum,gThisTarget,gHitId,"TAB",gIdNum); }
			if (returnedStorage.data.PE) gPE = returnedStorage.data.PE;
			if (returnedStorage.command=="ping") sendPongMessage(gThisTarget,gIdNum);
			if ( gScriptMode=="hitPage" && ( (gSubmitButton && gSubmitButton.length) || $(".btn-secondary:contains('Return')").length ) ) {
				if (!gButtonSet) { console.log("magic merlin: " + gScriptMode);
					gButtonSet = true;
					createDiv("Q").css({"position":"fixed","width":"10px","text-align":"right","height":"20px","top":"82px","right":"2px","float":"right","box-sizing":"content-box",
                        "padding":"0px 3px","background-color":"black","color":"white","opacity": "0.3","cursor":"pointer","font-size":"11px","line-height":"14px",
                        "font-family":"verdana, arial, sans-serif"}).disableSelection().click(function() { toggleOptionsMenu(); }).appendTo("body");
					createDiv("").css({"position":"fixed","width":"400px","height":"200px","top":"90px","right":"20px","float":"right","background-color":"#eceadf","border":"3px solid #000"}).attr({"id":"JR_QueueOptionsMenu"}).hide().appendTo("body");
					setupOptionsMenu();
					if (gHitId!=="") {
						sendDoingHitMessage(gQueueSessOptions.tabNum,gThisTarget,gHitId,"TAB",gIdNum);
					}
				}
				setNextHit();
			} else if (gScriptMode=="accepted" && gThisJob===null && !gNoHits) {
				gThisJob = grabJobData(99); sendAcceptedHitMessage(gThisTarget,gThisJob,gIdNum); setNextHit();
			}
		}
	}
}
function checkForNextNewHit() {
	if (gQueueData!==null) { // check if Panda Crazy returned the Queue Data.
		if (gLocation.indexOf("assignment_id=") != -1) gHitId = gLocation.split("assignment_id=")[1].split("&")[0]; // set global current hit id.
		var theNextHitIs = findNextHitQueue(gHitId,(gQueueSessOptions.nextIsSame) ? gPrevTitle : "",true);
		if (theNextHitIs && theNextHitIs.hitId!=gHitId) { // if next hit found and not the current hit then go to hit.
			console.log("going to: " + theNextHitIs.continueURL.replace("&ref=w_pl_prvw","&from_queue=true"));
			window.location.replace(theNextHitIs.continueURL.replace("&ref=w_pl_prvw","&from_queue=true"));
		} else {
			if (gScriptMode=="hitPage" && theNextHitIs && theNextHitIs.hitId!=gHitId) window.location.replace("https://worker.mturk.com/tasks");
			else $("body").children("div,table").css("opacity","1"); // undim page so user can work.
		}
	} else $("body").children("div,table").css("opacity","1"); // undim page so user can work.
}

clearOldTabMessages(); loadSessionData(); console.log("gLocation=" + gLocation);
if (gLocation.indexOf("worker.mturk.com") != -1) {
	gNewSite=true; console.log("on new site");// we are now on the new site.
	gScriptMode = checkNewMode();
	sessionStorage.removeItem("JR_queueOrder_hitID");
	window.addEventListener("storage", mainListener, false);
	$(function(){
		//$(window).load(function() {
            console.log("I am loaded: " + gReturnedHitID);
			if ($(".mturk-alert-content:contains('The HIT has been successfully submitted.')").length) { // Check if a hit was submitted.
				$("body").children("div,table").css("opacity","0.1"); // Dim the page so it looks busy thinking.
				gSubmitHitID = gPrevHit; // set global submitted variable for use in getting next hit.
				sendSubmittedMessage(gThisTarget,gPrevHit,gIdNum); // send submitted message to Panda Crazy.
				setTimeout(function() { checkForNextNewHit(); },600); // timer to lower the chance of pre's if redirecting or waiting for queue data
			}
			if (gReturnedHitID != "") { console.log("-- Returned Hit");
				$("body").children("div,table").css("opacity","0.1"); // Dim the page so it looks busy thinking.
				setTimeout(function() { checkForNextNewHit(); },600); // timer to lower the chance of pre's if redirecting or waiting for queue data
			}
			if (gScriptMode) {
				if ($(".btn-secondary:contains('Return')").length) { // only hit pages accepted will have a return button.
					$(".navbar-brand:first").after("<span style='margin-left:10px; font-size:11px;'>[ <a href='https://worker.mturk.com/tasks' style='color:cyan;'>Your HITs Queue</a> ]</span>");
					gHitId = gLocation.split("assignment_id=")[1].split("&")[0]; // grab the current hit id.
					$(".btn-secondary:contains('Return')").bind("click", function() { // detect a return click.
						sendReturnedMessage(gThisTarget,gHitId,gIdNum); // Tell Panda Crazy that hit has been returned.
						sessionStorage.setItem("JR_PC_QReturnedHitId",gHitId);
					});
					if (gScriptMode=="hitPage") sendDoingHitMessage(gQueueSessOptions.tabNum,gThisTarget,gHitId,"SD",gIdNum); // tell Panda Crazy doing this current hit for tab detection.
					var projectDetailBar = $(".project-detail-bar"), requestersInfo={}, theRequesterName = ""; // set variable to the detail bar to grab details.
					if (projectDetailBar.length) { // if found detail bar.
						var tempPrevDiv = projectDetailBar[0].getElementsByClassName("col-sm-4 col-xs-5"); // look for div with class names.
						var reactInfo = tempPrevDiv[0].querySelector("div").dataset.reactProps; // grab the details for this particular hit.
						if (reactInfo) { reactInfo = JSON.parse(reactInfo).modalOptions; theRequesterName = reactInfo.requesterName; gTitle = reactInfo.projectTitle; }
					}
					sessionStorage.setItem("JR_PC_QPrevHitId",gHitId); sessionStorage.setItem("JR_PC_QPrevTitle",gTitle); // set local variables for previous hit and title
					setInterval( function() {
						if (gQueueData!==null) { // Has Panda Crazy sent the current Queue Data?
							document.title = "( " + gCurrentPostion + "/" + gQueueData.length + " ) " + theRequesterName + " :: " + gOriginalTitle; // Change title constantly for changes.
						}
					},900);
				} else if ( (gScriptMode=="queuePageNextStart" || gScriptMode=="monitorQueue") &&
						!$(".no-result-row").length) { // If not an emppty queue and looking for next hit or monitoring queue.
					$("body").children("div,table").css("opacity","0.1"); gScriptMode="queuePageNextStart"; // dim page and set to looking for next hit.
					gQueueSessOptions.nextPosition="--"; gQueueSessOptions.nextIsLast=false; gQueueSessOptions.nextIsSame=false; saveSessionData(); // reset options.
					setTimeout(function() { queuePageNewStart(); },400); // find next hit but use timer to lessen chance of pre's.
				} else if (gScriptMode=="monitorQueue") { // wants to monitor empty queue for any new hits.
					sendQueuePageMessage(gThisTarget,gIdNum); // send Panda Crazy a queue send command.
					var refreshIntervalId = setInterval( function() { // set an interval to keep checking queue to find any new hits.
						if (gQueueData!==null && gQueueData.length>0) { // found a hit in the queue.
							clearInterval(refreshIntervalId); // stop the interval.
							speakThisNow("Hits in Queue. Going to first."); // alert user to a hit found.
							setTimeout(function() { window.location.replace(gQueueData[0].continueURL + "&from_queue=true"); },300); // go to the first hit in queue.
						}
					},800); // use a timer for interval and lessen chance of pre's if too fast.
				} else if (gScriptMode=="goToNum" || gScriptMode=="goLastHit") { // user looking for a specific hit in queue or the last one.
					setTimeout( function() {
						var queueDataDiv = $(".task-queue-header:first").next().find("div"); // set variable to queue header div to find queue list.
						var reactInfoList = queueDataDiv[1].dataset.reactProps, positionNum = 1; // set queue list variable
						if (reactInfoList) {
							queueData = JSON.parse(reactInfoList).bodyData; // convert the list to an array of objects.
							if (gScriptMode=="goLastHit") { // if looking for last hit.
								positionNum = queueData.length; // set position number to the last hit in queue.
							   gQueueSessOptions.nextPosition="--"; gQueueSessOptions.nextIsLast=true; gQueueSessOptions.nextIsSame=false; // reset options to look for last hit.
							} else { // must be looking for a specific position.
								var positionNumFirst = gLocation.split("JRPC=gohit")[1]; // find the go hit command to split it from the number.
								if (positionNumFirst) positionNum = positionNumFirst.match(/\d+/)[0]; // match the first number found and set variable to it.
								if (positionNum>0 && positionNum<26) { // make sure the number is 1 to 25 for queue position.
									gQueueSessOptions.nextPosition = positionNum; gQueueSessOptions.nextIsLast=false; gQueueSessOptions.nextIsSame=false; // reset options to look for next position.
								}
							}
							saveSessionData(); // save the options for the next hit.
							window.location.replace("https://worker.mturk.com" + queueData[positionNum-1].task_url + "&from_queue=true"); // go to the hit at the position set.
						}
					},1000);
				}
			}
	        window.onbeforeunload = function() { sendDoingHitMessage(gQueueSessOptions.tabNum,gThisTarget,gHitId,"D",gIdNum); };
            sendPingMessage(gThisTarget);
		//});
	});
} else {
	gScriptMode = checkMode();
	var goToNext = "";
	if (gLocation.indexOf("&prevsubmithitId=") != -1) { // Get previous hitId from the url and send submitted message to Panda Crazy.
		gSubmitHitID = (gLocation.split("&prevsubmithitId=")[1]).split("&")[0]; sendSubmittedMessage(gThisTarget,gSubmitHitID,gIdNum);
	}
	else if (gLocation.indexOf("mturk.com/mturk/submit") != -1 && gQueueNextHit && gQueueNextHit.prevId) { // Get previous and next hitId from the storageSession for hits that do not have an iframe.
		goToNext = "https://www.mturk.com/mturk/continue?hitId=" + gQueueNextHit.hitId; sendSubmittedMessage(gThisTarget,gQueueNextHit.prevId,gIdNum);
		$("body").html("");
	}
	if (gScriptMode=="returnPage") { // If on a return page then grab hitId from url and send returned message to Panda Crazy.
		gReturnedHitID = (gLocation.indexOf("hitId=") != -1) ? (gLocation.split("hitId=")[1]).split("&")[0] : "";
		sendReturnedMessage(gThisTarget,gReturnedHitID,gIdNum);
	}
	if (gScriptMode=="submitPage" || gScriptMode=="returnPage") { // if on submit page or return page get the next hit and go to that page after a second.
		if (gLocation.indexOf("&hitNextId=") != -1) goToNext = "https://www.mturk.com/mturk/continue?hitId=" + (gLocation.split("&hitNextId=")[1]).split("&")[0];
		if (goToNext!=="") { $("body").html(""); setTimeout(function() { window.location.replace(goToNext); },1100); }
		else if (gScriptMode=="returnPage" && gLocation.indexOf("&fromQueue=true") != -1) {
			$("body").html("");
			setTimeout(function() { window.location.replace("https://www.mturk.com/mturk/myhits?JRPC=nexthit"); },1100);
		}
	}
	sessionStorage.removeItem("JR_queueOrder_hitID");
	if (gScriptMode) {
		window.addEventListener("storage", mainListener, false);
		gHitReturnLink = $("a[href*='mturk/return']");
		gNoHits = ($("#alertboxMessage").length) ? ( (($("#alertboxMessage").html()).indexOf("There are no HITs in this group available") != -1) ? true : false) : false;
		gSubmitButton = document.getElementsByName("/submit");
		if (gSubmitButton.length || $(".btn-secondary:contains('Return')").length) {
			gHitExternalNextLink = $("#hitExternalNextLink"); gHitExternalNextAcceptLink = $("#hitExternalNextAcceptLink");
			gHitExternalNextLink.attr('href',gHitExternalNextLink.attr("href").replace("&sortType=&","&"));
			var returnLinkNode = $("img[src='/media/return_hit.gif']").closest("a");
			if (gScriptMode=="hitPage") returnLinkNode.attr('href',returnLinkNode.attr('href') + "&fromQueue=true");
			var capsuleNode = $("td.capsulelink_bold:first div").eq(0);
			var hitIdNode = $("input[name='hitId']");
			gHitId = (hitIdNode.length>0) ? $("input[name='hitId']").eq(0).val() : "";
			if (gScriptMode=="queuePageStart" || gScriptMode=="queuePageNextStart") sendDoingHitMessage(gQueueSessOptions.tabNum,gThisTarget,gHitId,"SD",gIdNum);
			gTitle = (capsuleNode.length) ? $(capsuleNode).html().trim() : "";
			setInterval( function() {
				var theTimer = $("#theTime").text();
				var theTimeLeftNode = $("a#time_left\\.tooltip");
				var theDuration = (theTimeLeftNode.length) ? theTimeLeftNode.parent().next().html().trim() : "";
				var requesterTip = $("#requester\\.tooltip");
				var requesterNameNode = (requesterTip.length) ? $(requesterTip).closest("tr").find(".capsule_field_text:first") : null;
				var theRequesterName = (requesterNameNode.length) ? $(requesterNameNode).text().trim() : "";
				setNextHit();
				gTabTextTimer+=1000;
				if (gTabTextTimer>=4000) {
					gTabTextTimer=0;
					gTabTextMode = 1 - gTabTextMode;
				}
				if (gQueueData!==null) document.title = "( " + gCurrentPostion + "/" + gQueueData.length + " ) " + theRequesterName + " :: " + gOriginalTitle;
			},1000);
		} else if (gScriptMode=="queuePageNextStart" || gScriptMode=="goLastHit" || gScriptMode=="goToNum") { setTimeout(function() { queuePageStart(); },300); }
		window.onbeforeunload = function() { sendDoingHitMessage(gQueueSessOptions.tabNum,gThisTarget,gHitId,"D",gIdNum); };
		sendPingMessage(gThisTarget);
		//setTimeout(function() { doYourQueue(); },1200);
	}
}