您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
A script add on for Panda Crazy for displaying queue and sorting queue after submitting hits.
当前为
// ==UserScript== // @name JR Mturk Panda Crazy Queue Helper // @version 0.3.0 // @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=* // @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.0", gQueueHelperFormat2 = true; var gScriptName="pandacrazy"; var gLocation=window.location.href; var gPandaCrazyLives=false, gHitExternalNextLink="", gHitExternalNextAcceptLink="", gTitle=""; var gPandaCrazyVersion=-1, gHitReturnLink="", gThisJob=null, gNoHits=false, gButtonSet=false; var gQueueData=null, gPE=0, gTabTextMode=0, gTabTextTimer=0, gOriginalTitle=document.title, gCurrentPostion = 1, 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 jobDataDefault={"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 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 && !thisDigit) ? true : false; if ((thisDigit || 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",false); 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 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)); 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() { if (gLocation.indexOf("mturk/myhits?JRPC=nexthit") != -1) return "queuePageNextStart"; else if (gLocation.indexOf("mturk/sortmyhits?JRPC=nexthit") != -1) return "queuePageNextStart"; else if (gLocation.indexOf("mturk/sortmyhits?") != -1) return "queuePageStart"; else if (gLocation.indexOf("mturk/myhits") != -1) return "queuePageStart"; else if (gLocation.indexOf("mturk/continue") != -1) return "hitPage"; else if (gLocation.indexOf("mturk/accept") != -1 && gLocation.indexOf("&prevHitSubmitted=") != -1) return "accepted"; else if (gLocation.indexOf("mturk/previewandaccept") != -1) return "accepted"; else if (gLocation.indexOf("mturk/preview") != -1) return "previewPage"; else if (gLocation.indexOf("mturk/submit") != -1) return "submitPage"; else if (gLocation.indexOf("mturk/return") != -1) return "returnPage"; 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, {}, jobDataDefault), 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.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.timeData); 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) 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) { if (!gQueueData || currentHitID === "") return null; sameDescription = sameDescription || ""; console.log( (sameDescription==="") ? "--EMPTY--" : 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); 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 (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[0]; else 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"}).append(hitsText).append(displayHits).appendTo(theMainContainer); 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 = "queuePageNext"; $("body").children("div,table").css("opacity","0.1"); if (!gPandaCrazyLives) console.log("no PC"); else console.log("PC found"); setTimeout(function() { var hitData = doSortResultsTable($("#sortresults_form")); if (hitData.length>0) { setTimeout(function() { window.location.replace(hitData[0].continueURL); },(!gPandaCrazyLives) ? 700 : 1); } else { $("body").children("div,table").css("opacity","1"); gScriptMode = "queuePage"; } },(!gPandaCrazyLives) ? 1 : 1000); } else gScriptMode = "queuePage"; } function setNextHit() { var targetHit = findNextHitQueue(gHitId, (gQueueSessOptions.nextIsSame) ? gTitle : ""); if (!targetHit && gQueueSessOptions.nextIsSame) targetHit = findNextHitQueue(gHitId, ""); if (targetHit) { var realHitId = $("input[name='hitId']").eq(0).val(); if (gHitExternalNextLink) $(gHitExternalNextLink).attr("href", targetHit.continueURL + "&prevsubmithitId=" + gHitId); if (gHitExternalNextAcceptLink) $(gHitExternalNextAcceptLink).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) { var theNextLinkHref = "/mturk/myhits?JRPC=nexthit"; if (theNextLinkHref.indexOf("&prevsubmithitId=") == -1) theNextLinkHref = theNextLinkHref + "&prevsubmithitId=" + gHitId; $(gHitExternalNextLink).attr('href', theNextLinkHref ); } if (gHitExternalNextAcceptLink) { $(gHitExternalNextAcceptLink).attr("href", gHitExternalNextAcceptLink.attr("href") + "&prevsubmithitId=" + gHitId); } } } function mainListener(e) { var returnedStorage = JSON.parse(e.newValue), messageSender=null; //console.log("[" + gPandaCrazyLives + "] | key: " + e.key + " | " + JSON.stringify(e.newValue)); 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_") { console.log("so an SD was found"); 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); else if (gSubmitButton.length && (gScriptMode=="hitPage" || gScriptMode=="previewPage")) { if (!gButtonSet) { gButtonSet = true; createDiv("Q").css({"position":"fixed","width":"10px","text-align":"right","height":"20px","top":"22px","right":"2px","float":"right","padding":"0px 3px","background-color":"black","color":"white","opacity": "0.3","cursor":"pointer"}).disableSelection().click(function() { toggleOptionsMenu(); }).appendTo("body"); createDiv("").css({"position":"fixed","width":"400px","height":"200px","top":"25px","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); console.log(JSON.stringify(gThisJob)); sendAcceptedHitMessage(gThisTarget,gThisJob,gIdNum); setNextHit(); } } } } clearOldTabMessages(); loadSessionData(); 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); } 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. //console.log("return page: " + gLocation); 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); },1300); } else if (gScriptMode=="returnPage" && gLocation.indexOf("&fromQueue=true") != -1) { $("body").html(""); gScriptMode = null; setTimeout(function() { window.location.replace("https://www.mturk.com/mturk/myhits?JRPC=nexthit"); },800); } } 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) { 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() : ""; gTabTextTimer+=1000; if (gTabTextTimer>=4000) { gTabTextTimer=0; gTabTextMode = 1 - gTabTextMode; } if (gQueueData!==null) document.title = "( " + gCurrentPostion + "/" + gQueueData.length + " ) " + theRequesterName + " :: " + gOriginalTitle; //console.log("Next link is now: " + $(gHitExternalNextLink).attr('href')); },1000); } else if (gScriptMode=="queuePageNextStart") { setTimeout(function() { queuePageStart(); },300); } window.onbeforeunload = function() { sendDoingHitMessage(gQueueSessOptions.tabNum,gThisTarget,gHitId,"D",gIdNum); }; sendPingMessage(gThisTarget); //setTimeout(function() { doYourQueue(); },1200); }