// ==UserScript==
// @name JR Mturk Panda Crazy
// @version 0.2.12
// @description Collects panda's for you at a certain cycle instead of timers. Lot of organizing of panda's and grouping them together to start and stop them at once.
// @author (JohnnyRS on mturkgrind.com and mturkcrowd.com) johnnyrs@allbyjohn.com
// @include http*://www.mturk.com/mturk/welcome?pandacrazy=on*
// @require http://code.jquery.com/jquery-2.1.4.min.js
// @require http://code.jquery.com/ui/1.11.4/jquery-ui.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery-layout/1.3.0-rc-30.79/jquery.layout.min.js
// @resource jQueryUICSS http://code.jquery.com/ui/1.11.4/themes/pepper-grinder/jquery-ui.css
// @resource jQueryLayoutCSS https://cdnjs.cloudflare.com/ajax/libs/jquery-layout/1.3.0-rc-30.79/layout-default.css
// @connect allbyjohn.com
// @connect mturk.com
// @connect tiny.cc
// @connect ibotta.com
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @grant GM_getResourceText
// @grant GM_setClipboard
// @namespace https://greasyfork.org/users/6406
// @downloadURL none
// ==/UserScript==
var gScriptVersion = "0.2.12";
var gScriptName = "pandacrazy";
var gDatabaseVersion = "JRAPR16-1.1-1.1.1"; // JR[Date]-[requesters DB Reset].[Alarms DB reset]-[requesters DB Version].[Options DB Version].[Tabs DB Version]
var gResetDBVersion = gDatabaseVersion.split("-")[1];
var gDefaultDBVersion = gDatabaseVersion.split("-")[2];
var gLocation = window.location.href;
var gSlowDownAuto = true;
var gResetAllData = false;
var gDelayedSave = false;
var gScriptStatus = "normal";
var gNotification = true;
var gFullQueue = false;
var gFullQueueTimer = null;
var gSavedSearchArea = "";
var gMyLayout = null, gAcceptedLogTab = null, gStatusLogTab = null, gQueueWatchTab = null, mCoinSound = [];
var gMainData = {"hitCollection":{},"displayInfo":"1","accepted":0,"skipped":0,"errors":0,"searched":0,"noHits":0,"fullQueue":0,"orphan":0,"tooFast":0,"savedCycleNum":1,
"hitsInQueue":0,"queueStatus":null,"notQual":0,"lastElapsed":0,"jobs":0,"payCounter":0,"projectedEarnings":0};
var gMainMenu = [{"name":"Main","theobject":null}];
var gDefaultRequestersOptions = {};
var gDefaultLayout = {};
var gDefaultSounds = {};
var gHitBgColor="#AFEEEE", gFilteredHitBgColor="#D1E5E5", gSearchesHitBgColor="#AED2D2", gButtonOffBgColor="#FFFFF0", gButtonOnBgColor="#008000";
var gButtonDelayHamBgColor="#00A3CC", gButtonDisabledBgColor="#D3D3D3", gHitMutedColor="#8B4513";
var gTitleColor="#000080", gButtonOffColor="black", gButtonOnColor="white", gButtonDisabledColor="#808080";
var gHitMutedBorderStyle="dotted", gHitBorderStyle="solid";
var gZingOptions = {
"0.01":{"SearchGroupAllowed":1,"TallyCountTotalAllowed":0,"MaxProductsSearch":0,"AcceptCodesSearching":false,"MaxReceiptImages":3},
"0.03":{"SearchGroupAllowed":2,"TallyCountTotalAllowed":0,"MaxProductsSearch":2,"AcceptCodesSearching":true,"MaxReceiptImages":3},
"0.05":{"SearchGroupAllowed":3,"TallyCountTotalAllowed":0,"MaxProductsSearch":4,"AcceptCodesSearching":true,"MaxReceiptImages":4},
"0.07":{"SearchGroupAllowed":7,"TallyCountTotalAllowed":0,"MaxProductsSearch":5,"AcceptCodesSearching":true,"MaxReceiptImages":8}
};
var gZingFuncOptions = {
"1":{"filterName":"Parse Zing Hit Page","functionName":parseZingHitPage}
};
var gAlarmSounds = {
"less2":{"nameVar":"JR_PANDA_Soundless2","default":"http://tiny.cc/c6c1ay","audio":null,"desc":"Hits paying less than |: ","payRate":"0.02","lessMinutes":"99"},
"less2Short":{"nameVar":"JR_PANDA_Soundless2Short","default":"http://tiny.cc/kyh1ay","audio":null,"desc":"Hits paying less than | with a short timer less than | minute(s): ","payRate":"0.02","lessMinutes":"2"},
"less5":{"nameVar":"JR_PANDA_Soundless5","default":"http://tiny.cc/g7h1ay","audio":null,"desc":"Hits paying less than |: ","payRate":"0.05","lessMinutes":"99"},
"less5Short":{"nameVar":"JR_PANDA_Soundless5Short","default":"http://tiny.cc/99h1ay","audio":null,"desc":"Hits paying less than | with a short timer less than | minute(s): ","payRate":"0.05","lessMinutes":"5"},
"less15":{"nameVar":"JR_PANDA_Soundless15","default":"http://tiny.cc/qai1ay","audio":null,"desc":"Hits paying less than |: ","payRate":"0.15","lessMinutes":"99"},
"less15Short":{"nameVar":"JR_PANDA_Soundless15Short","default":"http://tiny.cc/uai1ay","audio":null,"desc":"Hits paying less than | with a short timer less than | minute(s): ","payRate":"0.15","lessMinutes":"8"},
"less99":{"nameVar":"JR_PANDA_Soundless99","default":"http://tiny.cc/gbi1ay","audio":null,"desc":"Hits paying MORE than |: ","payRate":"0.15","lessMinutes":"99"},
"fullQueue":{"nameVar":"JR_PANDA_FullQueue","default":"http://tiny.cc/wietby","audio":null,"desc":"You have a full queue!","payRate":"","lessMinutes":"99"},
"queueAlert":{"nameVar":"JR_PANDA_QueueAlert","default":"http://tiny.cc/cnxyby","audio":null,"desc":"Lowest timed hit in queue is less than || minutes.","payRate":"","lessMinutes":"5"},
"hasToPause":{"nameVar":"JR_PANDA_hasToPause","default":"http://tiny.cc/w823by","audio":null,"desc":"Logged out or captcha alarm!","payRate":"","lessMinutes":"99"},
};
var gLastAlarm = "";
var gSoundFile = null;
var gTabIndex = 0;
var gMouseDownTimeoutId = null;
var gPressAndHold = false;
var gQueueData = [];
var gQueueCount = {};
var gMuteQueueWatch = false;
var gGroupings = {};
var gGroupingsSort = [];
var gGroupingData = {"JR First":{"theNumber":"0","description":"First grouping by default.","grouping":[],"delayed":[]}};
var gDefaultGroupingData = {"JR First":{"theNumber":"0","description":"First grouping by default.","grouping":[],"delayed":[]}};
var gTabsInfo = {};
var gDefaultTabsInfo = {"nextTabNumber":"4","tabCount":"3"};
var gTabsData = [];
var gDefaultTabsData = [{"tabName":"Main","tabNumber":"1","positions":null},{"tabName":"Daily Hits","tabNumber":"2","positions":null},{"tabName":"Rare Hits","tabNumber":"3","positions":null}];
var gMainOptions = {};
var gDefaultMainOptions = {"cycleNumber":980,"HamCycleNumber":700,"autoSlowDown":true,"cycleAutoIncrease":10,"alarmVolume":80,"cycleIncrease":10,"cycleDecrease":10,"cycleAdding":650,"queueTimer":40000,"hamDelayTimer":20,"showHelpTooltips":true,"cycleNumber2":1400,"cycleNumber3":2100};
var gRequestersData = {};
var jobDataDefault = {"requesterName":"","requesterId":"","groupId":"","pay":"","title":"","duration":"0","hitsAvailable":0,"timeLeft":"",
"continueURL":"","returnURL":"","durationParsed":null};
var gDefaultRequestersData = {
"0":{"requesterName":gDatabaseVersion,"requesterId":28,"action":"","groupId":"","pay":"","qual":"","title":"","queueLimit":0,"duration":"0","audioforce":"","dailyLimit":0,"mute":false,"position":null,"tabNumber":"1","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":0},
"4":{"requesterName":"Zing","requesterId":"AGVV5AWLJY7H2","action":"Panda","groupId":"30B721SJLR5BYYBNQJ0CVKJESN00OC","pay":"0.01","qual":"ibotta","title":"Are these the same?","queueLimit":0,"duration":"0","audioforce":"less2","dailyLimit":0,"mute":false,"position":null,"tabNumber":"2","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":15},
"5":{"requesterName":"Zing","requesterId":"AGVV5AWLJY7H2","action":"Panda","groupId":"30B721SJLR5BYYBNQJ0CVKJEQOZ0OB","pay":"0.01","qual":"","title":"Are these the same?","queueLimit":0,"duration":"0","audioforce":"less2","dailyLimit":0,"mute":false,"position":null,"tabNumber":"2","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":15},
"6":{"requesterName":"Zing","requesterId":"AGVV5AWLJY7H2","action":"Panda","groupId":"3ZXRRTK2NDCB5NW5M24C9P2OWG41OF","pay":"0.01","qual":"ibotta","title":"Does this receipt contain the following products?","queueLimit":0,"duration":"0","audioforce":"less2","dailyLimit":0,"mute":false,"position":null,"tabNumber":"2","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":8},
"7":{"requesterName":"Zing","requesterId":"AGVV5AWLJY7H2","action":"Panda","groupId":"3NYGPW9OTYRQLJTE9DQJQJRQJ2IZPS","pay":"0.01","qual":"","title":"Does this receipt contain the following products?","queueLimit":0,"duration":"0","audioforce":"less2","dailyLimit":0,"mute":false,"position":null,"tabNumber":"2","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":8},
"8":{"requesterName":"Zing","requesterId":"AGVV5AWLJY7H2","action":"Panda","groupId":"3R35RPFD7JUTQN8612HRYP7E6LZ1PV","pay":"0.03","qual":"ibotta","title":"Does this receipt contain the following products?","queueLimit":0,"duration":"0","audioforce":"less2","dailyLimit":0,"mute":false,"position":null,"tabNumber":"2","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":8},
"9":{"requesterName":"Zing","requesterId":"AGVV5AWLJY7H2","action":"Panda","groupId":"3ZXRRTK2NDCB5NW5M24C9P2OVF61OE","pay":"0.03","qual":"","title":"Does this receipt contain the following products?","queueLimit":0,"duration":"0","audioforce":"less2","dailyLimit":0,"mute":false,"position":null,"tabNumber":"2","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":8},
"10":{"requesterName":"Zing","requesterId":"AGVV5AWLJY7H2","action":"Panda","groupId":"3CRC4NO2BIQQWQ3GX0HLFPTFOD30SA","pay":"0.05","qual":"ibotta","title":"Does this receipt contain the following products?","queueLimit":0,"duration":"60 minutes","audioforce":"less2","dailyLimit":0,"mute":false,"position":null,"tabNumber":"2","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":12},
"11":{"requesterName":"Zing","requesterId":"AGVV5AWLJY7H2","action":"Panda","groupId":"3787DLY3Y49RIF1DIJQB3Z8BUNP1T2","pay":"0.05","qual":"","title":"Does this receipt contain the following products?","queueLimit":0,"duration":"0","audioforce":"less2","dailyLimit":0,"mute":false,"position":null,"tabNumber":"2","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":12},
"13":{"requesterName":"Viral Mturk","requesterId":"A2UFLDVZ75JD9M","action":"Panda","groupId":"3ZXEP6UEGGA75UPGRQ2UPK3XA4YO8B","pay":"0.25","qual":"","title":"Rate the quality of ads on YouTube","queueLimit":0,"duration":"0","audioforce":"","dailyLimit":0,"mute":false,"position":null,"tabNumber":"1","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":0},
"14":{"requesterName":"MyLikes","requesterId":"A239M0XNXTKQZ7","action":"Panda","groupId":"3EGCY5R6XY0PS57S4R2H1KZW7LSAYC","pay":"0.01","qual":"","title":"Identify Images with Mature Content","queueLimit":0,"duration":"0","audioforce":"","dailyLimit":0,"mute":false,"position":null,"tabNumber":"1","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":0},
"15":{"requesterName":"MyLikes","requesterId":"A239M0XNXTKQZ7","action":"Panda","groupId":"3USMLONC9E5D7T4TWRD6UWVBJLN85E","pay":"0.03","qual":"","title":"Identify Images with Mature Content","queueLimit":0,"duration":"0","audioforce":"","dailyLimit":0,"mute":false,"position":null,"tabNumber":"1","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":0},
"16":{"requesterName":"MyLikes","requesterId":"A239M0XNXTKQZ7","action":"Panda","groupId":"37G59K9AEU0BNMXNCLOH5POEZUC9YI","pay":"0.03","qual":"","title":"Identify Videos with Mature Content","queueLimit":0,"duration":"15 minutes","audioforce":"","dailyLimit":0,"mute":false,"position":null,"tabNumber":"1","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":0},
"17":{"requesterName":"Steven Snow","requesterId":"A3GAVAUPTHM0B8","action":"Panda","groupId":"3X19M43Z4VULD73G1I2N3GGRYF10D8","pay":"0.06","qual":"","title":"steven snow search 3X..D8","queueLimit":0,"duration":"0","audioforce":"","dailyLimit":0,"mute":false,"position":null,"tabNumber":3,"once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":0},
"18":{"requesterName":"Steven Snow","requesterId":"A3GAVAUPTHM0B8","action":"Panda","groupId":"3TJJ8HSJVIVGSMA3ZXVL0CV5EGV28D","pay":"0.05","qual":"","title":"steven snow url 3T..8D","queueLimit":0,"duration":"0","audioforce":"","dailyLimit":0,"mute":false,"position":null,"tabNumber":"3","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":0},
"19":{"requesterName":"Venue Quality","requesterId":"A14AT838CPSKA6","action":"Panda","groupId":"3EM4DVSA8U8J6KF08Q5EM8I2NYE308","pay":"0.01","qual":"","title":"locations same","queueLimit":0,"duration":"0","audioforce":"","dailyLimit":0,"mute":false,"position":null,"tabNumber":"1","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":0},
"20":{"requesterName":"Venue Quality","requesterId":"A14AT838CPSKA6","action":"Panda","groupId":"3D8O2NKTAGFJD90I499E0D26RON13W","pay":"0.01","qual":"","title":"locations adult","queueLimit":0,"duration":"5 minutes","audioforce":"","dailyLimit":0,"mute":false,"position":null,"tabNumber":"1","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":0},
"21":{"requesterName":"Venue Quality","requesterId":"A14AT838CPSKA6","action":"Panda","groupId":"ZZAWVTYW3Z9ZTAX43ZD0","pay":"0.01","qual":"","title":"locations family","queueLimit":0,"duration":"0","audioforce":"","dailyLimit":0,"mute":false,"position":null,"tabNumber":"1","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":0},
"22":{"requesterName":"Annabel","requesterId":"A3HB3KPJ2RZ2K8","action":"Panda","groupId":"3CVHT3IKTXQR8KSLQHD2N8KOQZPR06","pay":"0.50","qual":"","title":"Comparing two statements with each other","queueLimit":0,"duration":"60 minutes","audioforce":"","dailyLimit":0,"mute":false,"position":null,"tabNumber":"1","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":0},
"23":{"requesterName":"Rob Grady","requesterId":"AM07BBZNC6UTQ","action":"Panda","groupId":"33X7UBO5WUFB78Y5WJ3MVC35LFMU05","pay":"0.03","qual":"","title":"Transcribe Waffle House Guest Check","queueLimit":0,"duration":"5 minutes","audioforce":"","dailyLimit":0,"mute":false,"position":null,"tabNumber":"1","once":false,"dailyDone":0,"day":0,"filterMode":0,"hamTimer":20,"friendlyRName":"","friendlyTitle":"","queueHitLimit":0}
};
var gExcludeIds = ["38FT9G80DL83PUCSQBVANJBIKGSLHM"];
var jqUI_CssSrc = GM_getResourceText("jQueryUICSS");
var jqLayout_CssSrc = GM_getResourceText("jQueryLayoutCSS");
Date.prototype.stdTimezoneOffset = function() {
var jan = new Date(this.getFullYear(), 0, 1);
var jul = new Date(this.getFullYear(), 6, 1);
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
};
Date.prototype.dst = function() {
return this.getTimezoneOffset() < this.stdTimezoneOffset();
};
function formatAMPM(theFormat,theDate,theTimeZone) {
var d = (theDate) ? theDate : new Date();
if (theTimeZone == "mturk") {
var mturkTZOffset = -8;
var today = new Date();
if (today.dst()) mturkTZOffset++;
var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
var MturkTime = utc + (3600000 * mturkTZOffset);
d = new Date(MturkTime);
}
var minutes = d.getMinutes().toString().length == 1 ? '0'+d.getMinutes() : d.getMinutes(),
hours = d.getHours().toString().length == 1 ? '0'+d.getHours() : d.getHours(),
ampm = d.getHours() >= 12 ? 'pm' : 'am',
months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
days = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
if (theFormat=="short") return ('0' + (d.getMonth()+1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2) + '-' + d.getFullYear() + '(' + 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) {
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 checkNotifications() {
// Let's check if the browser supports notifications
if (!("Notification" in window)) return false;
else if (Notification.permission === "granted") return true;
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (permission === "granted") return true;
});
}
return false;
}
function showNotification( title, message, tag ) {
var n = new Notification(title, {
body: message,
icon: "http://www.allbyjohn.com/mturk/Messaging-Online-icon.png",
tag: tag});
if (navigator.userAgent.search("Chrome") >= 0) n.onshow = function () { setTimeout(n.close.bind(n), 20000); };
}
// Database using setValue and getValue
function convertDatabase(theDataBase) {
var newDataBase = {};
$.each(theDataBase, function( index, value ) {
newDataBase[index] = value;
if (newDataBase[index].action=="preta") newDataBase[index].action = "pantha";
});
newDataBase[0].requesterName = gDatabaseVersion;
return newDataBase;
}
function convertTabDatabase() {
if (gTabsData[0].tabName == "Holder") { // temporary for testing computer
var newDataBase = [];
gTabInfo = {"nextTabNumber":"" + gTabsData[0].tabNumber,"tabCount":"" + gTabsData.length};
$.each(gTabsData, function( index, value ) {
if (index>0) newDataBase.push(value);
});
gTabsData = newDataBase;
}
}
function getBase64Audio(theData) {
var base64AudioData = new Uint8Array(theData);
var i = base64AudioData.length;
var binaryString = new Array(i);
while (i--) { binaryString[i] = String.fromCharCode(base64AudioData[i]); }
var data = binaryString.join('');
return(window.btoa(data));
}
function loadSoundFiles(soundNumber,keyArray,resetMe) {
resetMe = resetMe || false;
var savedDBVersion = gRequestersData[0].requesterName;
var resetDBVersion = savedDBVersion.split("-")[1];
if (soundNumber < keyArray.length) {
if ((gResetDBVersion.split(".")[1] > resetDBVersion.split(".")[1]) || gResetAllData) GM_deleteValue(gAlarmSounds[keyArray[soundNumber]].nameVar);
var gotBase64 = (resetMe) ? null : GM_getValue(gAlarmSounds[keyArray[soundNumber]].nameVar,null);
this.firstTime = this.firstTime || false;
if (gotBase64 === null) {
if (!this.firstTime) addToWaitDialog("For your first time this might take a few seconds. Loading Alarms ",false);
this.firstTime = true;
requestUrl(gAlarmSounds[keyArray[soundNumber]].default,0,function(theResult,theNumber,data1,data2) {
addToWaitDialog(" .",false);
var base64 = getBase64Audio(theResult.response);
GM_setValue(gAlarmSounds[keyArray[soundNumber]].nameVar,JSON.stringify(base64));
gAlarmSounds[keyArray[soundNumber]].audio = new Audio("data:audio/wav;base64," + base64);
loadSoundFiles(soundNumber+1,keyArray,resetMe);
},function() { errorRequest(); }, "", "", "arraybuffer");
} else {
gAlarmSounds[keyArray[soundNumber]].audio = new Audio("data:audio/wav;base64," + JSON.parse(gotBase64));
loadSoundFiles(soundNumber+1,keyArray,resetMe);
}
} else continueLoading();
}
function fillInGroupings() {
$.each(gGroupingData, function( index, value ) {
if (!value.grouping) value.grouping = [];
gGroupings[index] = {"data":value,"collecting":false};
gGroupingsSort.push(index);
defaultFillIn(value,gDefaultGroupingData["JR First"]);
});
}
function defaultFillIn(data,defaultData) {
$.each(defaultData, function( index, value ) {
if (!(index in data)) { data[index] = value; }
});
}
function loadInDBVersions(passedDatabase) {
var tempData = null;
if (passedDatabase) tempData = passedDatabase;
else tempData = JSON.parse(GM_getValue("JR_PANDA_RequestersData",JSON.stringify(gDefaultRequestersData)));
var savedDBVersion = tempData[0].requesterName;
var resetDBVersion = savedDBVersion.split("-")[1];
var defaultDBVersion = savedDBVersion.split("-")[2];
if (gResetDBVersion.split(".")[0] > resetDBVersion.split(".")[0]) {
GM_deleteValue("JR_PANDA_RequestersData");
tempData = JSON.parse(GM_getValue("JR_PANDA_RequestersData",JSON.stringify(gDefaultRequestersData)));
}
tempData = convertDatabase(tempData);
$.each(tempData, function( index, value ) { defaultFillIn(value,gDefaultRequestersData[0]); });
return tempData;
}
function changeOldSettings() {
if (gMainOptions.cycleNumber==970) gMainOptions.cycleNumber = 980;
if (gMainOptions.cycleIncrease==5) gMainOptions.cycleIncrease = 10;
if (gMainOptions.cycleDecrease==5) gMainOptions.cycleDecrease = 10;
}
function loadSettings() {
if (gResetAllData) GM_deleteValue("JR_PANDA_RequestersData");
gRequestersData = loadInDBVersions();
if (gResetAllData) GM_deleteValue("JR_PANDA_MainOptions");
gMainOptions = JSON.parse(GM_getValue("JR_PANDA_MainOptions",JSON.stringify(gDefaultMainOptions)));
defaultFillIn(gMainOptions,gDefaultMainOptions);
if (gResetAllData) GM_deleteValue("JR_PANDA_TabsData");
gTabsData = JSON.parse(GM_getValue("JR_PANDA_TabsData",JSON.stringify(gDefaultTabsData)));
gTabsInfo = JSON.parse(GM_getValue("JR_PANDA_TabsInfo",JSON.stringify(gDefaultTabsInfo)));
convertTabDatabase();
$.each(gTabsData, function( index, value ) { defaultFillIn(value,gDefaultTabsData[0]); });
if (gResetAllData) GM_deleteValue("JR_PANDA_GroupingData");
gGroupingData = JSON.parse(GM_getValue("JR_PANDA_GroupingData",JSON.stringify(gDefaultGroupingData)));
fillInGroupings();
loadSoundFiles(0,Object.keys(gAlarmSounds));
changeOldSettings();
}
function fillInSoundOptions(soundOptions) {
$.each(soundOptions, function( index, value ) {
gAlarmSounds[index].payRate = value.payRate;
gAlarmSounds[index].lessMinutes = value.lessMinutes;
});
}
function setupSoundOptions() {
var soundOptions = {};
$.each(gAlarmSounds, function( index, value ) {
soundOptions[index] = {"payRate":value.payRate,"lessMinutes":value.lessMinutes};
});
return soundOptions;
}
function saveSettings(doAfter) {
var soundOptions = setupSoundOptions();
GM_setValue("JR_PANDA_RequestersData",JSON.stringify(gRequestersData));
GM_setValue("JR_PANDA_MainOptions",JSON.stringify(gMainOptions));
GM_setValue("JR_PANDA_TabsData",JSON.stringify(gTabsData));
GM_setValue("JR_PANDA_TabsInfo",JSON.stringify(gTabsInfo));
GM_setValue("JR_PANDA_GroupingData",JSON.stringify(gGroupingData));
GM_setValue("JR_PANDA_SoundOptions",JSON.stringify(soundOptions));
if (doAfter) setTimeout( function() { doAfter(); },200);
}
function checkDelayedSave() { if (gDelayedSave) saveSettings(); }
// Jquery Creating HTML elements Functions --------
function toggleButton(thisButton,doThisOn,doThisOff,mode,modeStatus) {
// dothison = status on function, dothisOff = status off function, mode = status mode to force change to, modestatus = force on or off function
var theStatus = $(thisButton).data("status"); // Get status of the button
var doStatus = (modeStatus) ? modeStatus : (theStatus != "on" && theStatus!=mode) ? "on" : "off";
if (mode && theStatus!=mode) $(thisButton).data("status",mode);
else $(thisButton).data("status",doStatus);
if (doStatus=="on" && doThisOn) doThisOn($(thisButton).data("theNumber"),thisButton,mode);
if (doStatus=="off" && doThisOff) doThisOff($(thisButton).data("theNumber"),thisButton,mode);
updateHitColors($(thisButton).data("theNumber"),thisButton);
}
function toggleButtonOff(thisButton,doThisOn,doThisOff,passedMode) {
$(thisButton).data("status","off");
updateHitColors($(thisButton).data("theNumber"),thisButton);
if (doThisOff) doThisOff($(thisButton).data("theNumber"),thisButton,passedMode);
}
function toggleButtonOn(thisButton,doThisOn,doThisOff) {
if ($(thisButton).data("status") == "off") {
$(thisButton).data("status","on");
updateHitColors($(thisButton).data("theNumber"),thisButton);
if (doThisOn) doThisOn($(thisButton).data("theNumber"),thisButton);
}
}
function checkButtonsStatus() {
if (gScriptStatus == "normal") return true;
else return false;
}
function createDiv(theHtml) { var inner = (theHtml) ? theHtml : ""; return $('
");
var tabsContainer = createContainer()
.attr("id",idName)
.css({"height":"99%"})
.appendTo(goAppend);
tabList.appendTo(tabsContainer);
tabsContainer.tabs().delegate( "span.ui-icon-close", "click", function(e) {
var currentTab = $(e.target).closest("li");
var currentIndex = $(currentTab).index();
$("#JRMainTabs").tabs("option", "active", currentIndex);
var returnValue = confirm("Are you sure you want to delete this Tab?\nAll hits inside the tab will be moved to the Main Tab.\nNo Hits will be lost.");
if (returnValue) {
var currentAriaTab = $("#" + (currentTab.attr("aria-controls")));
var mainAriaTab = $("#" + ($("#JRTab_1").attr("aria-controls")));
var currentData = $(currentTab).data("tabData");
$(currentTab).find(".JRHitDummy").remove();
$(mainAriaTab).find(".JRHitDummy").remove();
if (currentData.positions.length>0) {
for (var i=0, len=currentData.positions.length; i").html("" + theTitle + "")
.attr({"id":theID,"class":theClasses})
.css({"font-size":"10px"})
.data({"tabData":tabData})
.appendTo( tabContainer.find("ul") );
if (appendClose) {
theTabLi.append(createSpan("Remove Tab").attr({"class":"ui-icon ui-icon-close","role":"presentation"}));
theTabLi.bind("contextmenu", function(e) {
if ($(e.target).closest("li").index() > 0) {
var returnName = prompt("Enter Tab Label : ", $(e.target).html());
if (returnName) {
$(e.target).html(returnName);
$(e.target).closest("li").data("tabData").tabName = returnName;
saveSettings();
}
}
e.preventDefault();
return false;
});
}
theTabDiv.data({"tabData":tabData}).appendTo(tabContainer);
if (isSortable) {
theTabLi.click( function() { $(this).focus(); $(this).find(".tabContents").focus(); })
.droppable({
tolerance: 'pointer',
over: function( event, ui ) {
$("#JRMainTabs").tabs("option", "active", $(event.target).index());
$(event.target).focus(); $(event.target).find(".tabContents").focus();
}
});
theTabDiv.html(" ");
}
tabContainer.tabs("refresh");
return theTabDiv;
}
// Alarm function -----------
function playThisSound( keyName ) {
gLastAlarm = keyName;
gAlarmSounds[keyName].audio.pause();
gAlarmSounds[keyName].audio = gAlarmSounds[keyName].audio;
gAlarmSounds[keyName].audio.currentTime = 0;
gAlarmSounds[keyName].audio.volume = gMainOptions.alarmVolume/100;
gAlarmSounds[keyName].audio.play();
}
function playNewSound( AudioObject ) {
if (gSoundFile) gSoundFile.pause();
gSoundFile = AudioObject;
gSoundFile.currentTime = 0;
gSoundFile.volume = gMainOptions.alarmVolume/100;
gSoundFile.play();
}
// Main cycler class thaty handles all timers, queues, pauses, and hams
var theCycler = (function() {
var privateVars = {
_timers: [],
_theQueue: [],
_theFrontOfTheLineQueue: [],
_theFrontOfTheLineTimer: [],
_before: new Date(),
_theCycle: 500,
_realCycle: 500,
_theCycleElapsed: 0,
_theCycleSkipping: 0,
_paused: false,
_hamNumber: 0,
_timeoutVar: null
};
var privateFunctions = {
_getInTimer: function(theNumber) {
for (var i=0, len=privateVars._timers.length; i= privateVars._timers[i].milliSeconds) {
returnStatus = privateVars._timers[i].runFunction.apply("timer",[privateVars._timers[i].elapsed,privateVars._timers[i].theNumber] );
privateVars._timers[i].elapsed = 0;
}
}
return returnStatus;
},
_doQueue: function() {
var skipThis = true;
var firstNumber = privateVars._theQueue[0].theNumber;
do {
var queueItem = privateVars._theQueue.shift();
if (!queueItem.doOnce) privateVars._theQueue.push(queueItem);
skipThis = !queueItem.runFunction.apply("queue",[privateVars._theCycleElapsed,queueItem.theNumber] );
} while (privateVars._theQueue.length > 0 && skipThis && firstNumber != privateVars._theQueue[0].theNumber);
},
_theLoop: function() {
var continueCheck = true;
var elapsed = new Date().getTime() - privateVars._before.getTime();
if (elapsed >= privateVars._realCycle) {
privateVars._theCycleElapsed = elapsed;
privateVars._before = new Date();
if (privateVars._theFrontOfTheLineTimer.length > 0) continueCheck = !privateFunctions._goFrontOfTheLineTimer();
if (privateVars._theFrontOfTheLineQueue.length > 0) continueCheck = !privateFunctions._goFrontOfTheLine();
if (continueCheck && privateVars._timers.length>0) continueCheck = !privateFunctions._doTimers();
if (continueCheck && privateVars._hamNumber !== 0) { continueCheck = false; privateFunctions._goHam(); }
if (continueCheck && privateVars._theQueue.length>0) {
privateFunctions._doQueue();
}
}
privateVars._timeoutVar = setTimeout(privateFunctions._theLoop, 0);
}
};
var output = {
addJob: function(func, theNumber, milliSeconds, doOnce) {
if (typeof func === 'function' && !isNaN(milliSeconds)) {
doOnce = doOnce || false;
if (privateFunctions._checkInQueue(theNumber)!=-1) return;
for(var i=0, len=privateVars._timers.length; i 0) privateVars._timers.unshift(jobData);
}
if (privateVars._timeoutVar===null) { privateVars._before = new Date(); privateFunctions._theLoop(); }
},
removeJob: function(theNumber) {
var returnValue = false;
privateFunctions._removeFromQueue(theNumber);
for (var i=0, len=privateVars._timers.length; i0 || privateVars._theQueue.length>0)
privateVars._timeoutVar = setTimeout(privateFunctions._theLoop, 0);
},
frontOfTheLineTimer: function( theNumber ) { privateVars._theFrontOfTheLineTimer.push(theNumber); },
frontOfTheLine: function( theNumber ) { privateVars._theFrontOfTheLineQueue.push(theNumber); },
hamOn: function( theNumber ) { privateVars._hamNumber = theNumber; },
hamOff: function() { privateVars._hamNumber = 0; },
isHamOn: function() { return (privateVars._hamNumber>0) ? true : false; },
jobs: function() { return privateVars._theQueue.length; },
skippingReset: function() { privateVars._theCycleSkipping = 0; privateVars._realCycle = privateVars._theCycle; },
cycleIncrease: function(increaseNumber) {
increaseNumber = increaseNumber || gMainOptions.cycleIncrease;
privateVars._theCycleSkipping += parseInt(increaseNumber);
privateVars._realCycle += parseInt(increaseNumber);
},
cycleDecrease: function(decreaseNumber) {
decreaseNumber = decreaseNumber || gMainOptions.cycleDecrease;
privateVars._theCycleSkipping = (privateVars._theCycleSkipping > 0) ?
privateVars._theCycleSkipping -= parseInt(decreaseNumber) : 0;
privateVars._realCycle = privateVars._theCycle + privateVars._theCycleSkipping;
},
cycle: function() { return privateVars._theCycle; },
cycleSkipping: function() { return privateVars._theCycleSkipping; },
cycleChange: function(newSkipping) {
privateVars._theCycleSkipping = newSkipping; privateVars._realCycle = privateVars._theCycle + privateVars._theCycleSkipping;
},
cycleAdd: function(newSkipping) {
privateVars._theCycleSkipping += newSkipping; privateVars._realCycle = privateVars._theCycle + privateVars._theCycleSkipping;
},
cycleResetChange: function(newCycle) {
privateVars._theCycle = newCycle; privateVars._theCycleSkipping = 0; privateVars._realCycle = newCycle;
}
};
return output;
})();
// status on UI to show info to user.
function displayMainStatus() {
var statusText = "", theMode="";
var theJobs = (gMainData.jobs===0) ? "-- No Jobs to Search. " : "-- Running: " + gMainData.jobs + " jobs ";
$("#JRJobsArea").html(theJobs);
theMode = $("#JRCycleInfoArea").data("mode");
var theCycle = (theMode=="Elapsed") ? "[ Elapsed Time: " + gMainData.lastElapsed + "ms | " :
(theMode=="Cycle") ? "[ Cycling every: " + theCycler.cycle() + "ms | " :
(theMode=="CycleSkipping") ? "[ Cycling Slowed: " + theCycler.cycleSkipping() + "ms | " :
(theMode=="Hamcycle") ? "[ Min Ham Cycle: " + gMainOptions.HamCycleNumber + "ms | " : "";
if (isActiveMenu(gMainMenu,"Cycler")) {
theCycle = "[ Elapsed Time: " + gMainData.lastElapsed + "ms | Cycling every: " + theCycler.cycle() + "ms | Cycling Slowed: " +
theCycler.cycleSkipping() + "ms | Min Ham Cycle: " + gMainOptions.HamCycleNumber + "ms ]";
$("#JRCycleInfoArea").html(theCycle);
$("#JRResultAccSkipArea").html("");
$("#JRErrorArea").html("");
$("#JRMturkQueueArea").html("");
$("#JRSearchedArea").html("");
$("#JRPayArea").html("");
} else {
$("#JRCycleInfoArea").html(theCycle);
theMode = $("#JRResultAccSkipArea").data("mode");
var theAccSkip = (theMode=="Accepted") ? "Accepted: " + gMainData.accepted + " | " :
(theMode=="Skipped") ? "Skipped: " + gMainData.skipped + " | " : "";
$("#JRResultAccSkipArea").html(theAccSkip);
theMode = $("#JRErrorArea").data("mode");
var theErrors = (theMode=="Errors") ? "Errors: " + gMainData.errors + " | " :
(theMode=="TooFast") ? "Too Fast: " + gMainData.tooFast + " | " : "";
$("#JRErrorArea").html(theErrors);
$("#JRMturkQueueArea").html("Mturk Queue: " + ((parseInt(gMainData.hitsInQueue)<25) ? gMainData.hitsInQueue : "Full") + " | ");
$("#JRSearchedArea").html("Searched: " + gMainData.searched + " | ");
theMode = $("#JRPayArea").data("mode");
var thePay = (theMode=="PayAccepted") ? "Pay Accepted: $" + gMainData.payCounter.toFixed(2) + " ]" :
(theMode=="Projected") ? "Projected Earnings: $" + gMainData.projectedEarnings.toFixed(2) + " ]" : "";
$("#JRPayArea").html(thePay);
}
}
function createQueueLinks(returnUrl,continueUrl) {
var theLinks = createSpan(createLink("Return",returnUrl,"_blank","Return").attr({"class":"JRQueueReturn"})
.click( function(e) {
gAlarmSounds.queueAlert.audio.pause();
showYesNoDialog("Are you sure you want to return this hit?",function() {
var theHeight=window.outerHeight-80, theWidth=window.outerWidth-10;
window.open($(e.target).attr("href"),"_blank","width=" + theWidth + ",height=" + theHeight + ",scrollbars=yes,toolbar=yes,menubar=yes,location=yes");
});
return false;
})).append(createSpan(" :: "));
theLinks = theLinks.append(createSpan(createLink("Continue Work",continueUrl,"_blank","Continue Work").attr({"class":"JRQueueContinue"})
.click( function(e) {
gAlarmSounds.queueAlert.audio.pause();
var theHeight=window.outerHeight-80, theWidth=window.outerWidth-10;
window.open($(e.target).attr("href"),"_blank","width=" + theWidth + ",height=" + theHeight + ",scrollbars=yes,toolbar=yes,menubar=yes,location=yes");
return false;
})));
return theLinks;
}
function displayQueueStatus() {
addToQueueWatchLog(createSpan(""),true);
var lessThanAlarm = false;
gQueueData.reverse();
if (gQueueData.length>0) {
for (var i=0, len=gQueueData.length; i" +
gQueueData[i].timeLeft + "
- " + gQueueData[i].title + " :: ").data("thisData",gQueueData[i])
.append(createQueueLinks(gQueueData[i].returnURL,gQueueData[i].continueURL)));
var theTimeLeft = getTimeLeft(gQueueData[i].timeLeft);
if (!lessThanAlarm && theTimeLeft.weeks < 1 && theTimeLeft.days < 1 && theTimeLeft.hours < 1 && theTimeLeft.minutes < parseInt(gAlarmSounds.queueAlert.lessMinutes)) {
lessThanAlarm = true;
if (!$("#muteQueueWatchAlarm").is(":checked")) {
playThisSound("queueAlert");
$("#JRQueueWatchLog").css({"background-color":"#8A0000"});
$("#JRQueueWatchLog").animate({backgroundColor:"#000000"}, 10000, function() {
$("#JRQueueWatchLog").css({"background-color":"#8A0000"});
$("#JRQueueWatchLog").animate({backgroundColor:"#000000"}, 10000);
});
}
}
}
} else {
addToQueueWatchLog(createDiv("You have no hits in your queue at this time. All your hits in your queue will be in this section. " +
"An alarm will be heard if a hit has " + gAlarmSounds.queueAlert.lessMinutes + " minutes left. Mute the alarm to the right if not needed. " +
"You can also change the alarm and the minutes left in the options/alarms menu at top.")
.css({"font-size":"16px","color":"#7FFFD4","margin-top":"12px","text-align":"center","line-height":"18px"}));
}
$("#JRStatusTab_2 .JRTabLabel:first").html("Queue Watch - " + ((gMainData.hitsInQueue <=25) ? gMainData.hitsInQueue : "25"));
}
function fullQueueTimer() { gFullQueue = false; }
function displayHitStatus( theNumber ) {
var hitInfo = gMainData.hitCollection[theNumber];
var hitStatus = hitInfo.status;
var skippedStatus = (hitInfo.data.action.toLowerCase().indexOf("filter") != -1) ? "Skip: " + hitStatus.skipped + " | " : "";
var missedStatus = (hitInfo.data.action.toLowerCase().indexOf("pantha") != -1) ? "Miss: " + hitStatus.missed + " | " : "";
var statusText = "[ Acc: " + hitStatus.accepted + " | " + skippedStatus + missedStatus + "Srch: " + hitStatus.searched + " ] ";
$("#JRCellStatus_" + theNumber).html( statusText );
displayMainStatus();
}
function processResults( theNumber, result ) {
var hitInfo = (theNumber>0) ? gMainData.hitCollection[theNumber] : null;
var hitData = (hitInfo) ? hitInfo.data : null;
var hitStatus = (hitInfo) ? hitInfo.status : null;
switch(result) {
case "NOTQUALIFIED":
if (hitStatus) hitStatus.notQual++;
gMainData.notQual++;
break;
case "NOACCEPT":
if (hitStatus && hitData && hitData.action.toLowerCase().substring(0,6) == "search") { hitStatus.missed++; hitStatus.noHits++; }
break;
case "NOMORE":
if (hitStatus) hitStatus.noHits++;
if (hitStatus && hitData && hitData.action.toLowerCase().substring(0,6) == "search") hitStatus.missed++;
gMainData.noHits++;
break;
case "TOOFAST":
if (hitStatus) hitStatus.tooFast++;
gMainData.tooFast++;
if (gSlowDownAuto) theCycler.cycleIncrease(gMainOptions.cycleAutoIncrease);
break;
case "LOGGEDOFF":
if (!theCycler.isPaused()) {
var addText = createDiv("You are logged out of Amazon.
Can't accept hits so pausing.
Please log back in!")
.css({"margin-top":"30px","font-size":"17px","text-align":"center","color":"red"})
.append(createDiv(createLink("Go to Mturk Page","https://www.mturk.com/mturk/myhits","_blank","https://www.mturk.com/mturk/myhits")
.click( function() {
window.open("https://www.mturk.com/mturk/myhits","_blank","width=" + 1000 + ",height=" + 800 + ",scrollbars=yes,toolbar=yes,menubar=yes,location=yes");
return false;
})).css({"color":"blue","margin-top":"15px"}));
showWaitDialog("Logged Out!!","",function() {
theCycler.unpause();
$("#JRPauseButton").html("Pause").css({"background-color":"ivory","color":"black"});
},null,addText,true);
theCycler.pause();
$("#JRPauseButton").html("Resume").css({"background-color":"red","color":"white"});
playThisSound("hasToPause");
}
break;
case "DAILYLIMIT":
theCycler.pause();
$("#JRPauseButton").html("Resume").css({"background-color":"red","color":"white"});
alert("Congratulations!! You have reached your daily limit. Wait for tomorrow.");
break;
case "NOTCOMPLETED":
case "ERROR":
if (hitStatus) hitStatus.error++;
gMainData.error++;
break;
case "QUEUEMAX":
if (hitStatus) hitStatus.fullQueue++;
if (!gFullQueue) {
playThisSound("fullQueue");
gFullQueueTimer = setTimeout( function() { fullQueueTimer(); }, 240000 );
}
gFullQueue = true;
gMainData.fullQueue++;
break;
case "SKIPPED":
if (hitStatus) hitStatus.skipped++;
gMainData.skipped++;
break;
case "ACCEPTED":
if (hitStatus) hitStatus.accepted++;
if (hitData.hamTimer > 0) hitInfo.lastAccept = new Date();
var newDate = new Date().setHours(0,0,0,0);
if (hitData.dailyLimit && hitData.dailyLimit>0) hitData.dailyDone = (newDate == hitData.day) ? hitData.dailyDone + 1 : 1;
if (hitData.once) hitData.dailyDone = 1;
hitData.day = newDate;
gMainData.accepted++;
gMainData.hitsInQueue++;
thisKey = hitData.requesterName + ":" + hitData.title;
gQueueCount[thisKey] = (thisKey in gQueueCount) ? gQueueCount[thisKey]+1 : 1;
if (hitData.duration.indexOf("second") == -1) hitData.duration = hitData.duration + " 0 seconds";
addToQueueWatchLog(createSpan("(" + hitData.requesterName + ") [$" + hitData.pay + "] - " +
hitData.duration + " - " + hitData.title + " :: ").data("thisData",hitData).append(createQueueLinks(returnLink(hitInfo.hitId),continueLink(hitInfo.hitId))),
(gMainData.hitsInQueue>1) ? false : true);
$("#JRStatusTab_2 .JRTabLabel:first").html("Queue Watch - " + ((gMainData.hitsInQueue <=25) ? gMainData.hitsInQueue : "25"));
var hitPay = parseFloat(hitData.pay);
gMainData.payCounter = Math.round( (gMainData.payCounter + hitPay) * 100) / 100;
gMainData.projectedEarnings = Math.round( (gMainData.projectedEarnings + hitPay) * 100) / 100;
var theDuration = hitInfo.minutes;
if (theDuration===0 && hitData.duration!="0") {
theDuration = (hitData.duration.indexOf("weeks")!=-1) ? 5000 : (hitData.duration.indexOf("day")!=-1) ? 1500 : (hitData.duration.indexOf("hours")!=-1) ? 200 :
(hitData.duration.indexOf("hour")!=-1) ? 60 : (hitData.duration.indexOf("minutes")!=-1) ? parseInt(hitData.duration.split("minutes")[0]) : 1;
hitInfo.durationParsed = getTimeLeft(hitData.duration);
hitInfo.minutes = theDuration;
}
var theSoundFile = "less99";
var notificationTitle = "Accepted Hit From: " + hitData.requesterName;
var notificationMessage = "Pay: " + hitData.pay + "\nDuration: " + hitData.duration + "\nTitle: " + hitData.title;
if (!hitData.mute) {
if ( hitPay < parseFloat(gAlarmSounds.less2.payRate) ) {
theSoundFile = (theDuration !== 0 && theDuration<=parseInt(gAlarmSounds.less2Short.lessMinutes)) ? "less2Short" : "less2";
} else if ( hitPay <= parseFloat(gAlarmSounds.less5.payRate) ) {
theSoundFile = (theDuration !== 0 && theDuration<=parseInt(gAlarmSounds.less5Short.lessMinutes)) ? "less5Short" : "less5";
} else if ( hitPay <= parseFloat(gAlarmSounds.less15.payRate) ) {
theSoundFile = (theDuration !== 0 && theDuration<=parseInt(gAlarmSounds.less15Short.lessMinutes)) ? "less15Short" : "less15";
} else if ( hitPay < parseFloat(gAlarmSounds.less99.payRate) ) { theSoundFile = "less99"; }
if (hitData.audioforce !== "") theSoundFile = hitData.audioforce;
playThisSound(theSoundFile);
}
if (gScriptStatus == "normal") {
$("#JRCellNum_" + theNumber).stop(true,true);
$("#JRCellNum_" + theNumber).css({"background-color":"yellow"});
$("#JRCellNum_" + theNumber).animate({backgroundColor: $("#JRCellNum_" + theNumber).data("backgroundColor")}, 40000);
}
if (gNotifications) showNotification( notificationTitle, notificationMessage, "accepted");
if ( hitInfo.ham == "paused" ) toggleButton($("#JRHamB_" + theNumber),hamOn,hamOff);
addToAcceptedLog( hitData.requesterName + " - " + hitData.groupId + " - " + hitData.title );
updateHitCell(theNumber);
break;
}
if (theNumber > 0) displayHitStatus(theNumber);
}
function requestUrl(theUrl, theNumber, theFunction, errorFunction, data1, data2, theResponseType) {
theResponseType = theResponseType || "";
//console.log("JR going to get: " + theUrl);
GM_xmlhttpRequest({
method: "GET",
url: theUrl,
responseType: theResponseType,
onload: function(response) { if (typeof theFunction == 'function') theFunction(response,theNumber,data1,data2); },
onerror: function(response) { if (typeof errorFunction == 'function') errorFunction(response,theNumber); }
});
}
function pandaLink(theGroupId) { return "https://www.mturk.com/mturk/previewandaccept?groupId=" + theGroupId; }
function previewLink(theGroupId) { return "https://www.mturk.com/mturk/preview?groupId=" + theGroupId; }
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 requesterSearch(theRequester) { return "https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&qualifiedFor=on&sortType=Reward%3A1&requesterId=" + theRequester; }
function acceptLink(theHitData) { return "https://www.mturk.com/mturk/accept?hitId=" + theHitData.hitId + "&prevHitSubmitted=" + theHitData.prevHitSubmitted +
"&prevRequester=" + theHitData.prevRequester + "&prevReward=" + theHitData.prevReward + "&requesterId=" + theHitData.requesterId + "&groupId=" +
theHitData.groupId + "&signature=" + theHitData.signature;
}
function checkLimits(theNumber) {
//console.log("JR checking " + theNumber + " for their limits.");
var hitInfo = gMainData.hitCollection[theNumber];
var hitData = hitInfo.data;
var returnValue = false;
var theKey = hitData.requesterName + ":" + hitData.title;
if (hitData.queueLimit === 0 && hitData.queueHitLimit === 0 && hitData.dailyLimit === 0 && !hitData.once) returnValue = true;
else if (hitData.once && hitData.dailyDone>0) {
if (hitInfo.hitCell.data("status")=="on") hitInfo.hitCell.data("status","off");
toggleButtonOff( hitInfo.hitCell.find(".JRCollectButton"),startCollecting,stopCollecting);
returnValue = false; }
else if (hitData.queueHitLimit > 0 && (gQueueCount[theKey] === "undefined" || gQueueCount[theKey] >= hitData.queueHitLimit)) returnValue = false;
else if (hitData.queueLimit > 0 && hitData.queueLimit <= gMainData.hitsInQueue) returnValue = false;
else if (hitData.dailyLimit > 0 && hitData.dailyLimit < gMainData.dailyDone) returnValue = false;
else returnValue = true;
return returnValue;
}
function searchRequestersInfo( theNumber, hitNumber, requestersInfo ) {
var hitInfo = gMainData.hitCollection[hitNumber];
var hitData = hitInfo.data;
if (hitInfo.collecting != "off") {
hitInfo.status.searched++;
displayHitStatus(hitNumber);
for (var i=0, len=requestersInfo.data.length; i tbody > tr").each(function(i, row) {
var jobData = jQuery.extend(true, {}, jobDataDefault);
var titleElement = $(row).find("#capsule" + i + "-0");
if (titleElement.length) {
jobData.title = $(titleElement).text().trim();
var titleLink = $(titleElement).closest("tr").find(".capsulelink a:first");
jobData.groupId = (titleLink.length) ? $(titleLink).attr("href").split("groupId=")[1] : "";
var returnLink = $(titleElement).closest("tr").find("a:contains('Return this HIT'):first");
jobData.returnURL = (returnLink.length) ? "https://www.mturk.com" + $(returnLink).attr("href") : "";
var continueLink = $(titleElement).closest("tr").find("a:contains('Continue work on this HIT'):first");
jobData.continueURL = (continueLink.length) ? "https://www.mturk.com" + $(continueLink).attr("href") : "";
var requesterElement = $(row).find(".requesterIdentity:first");
jobData.requesterName = (requesterElement.length) ? $(requesterElement).text().trim() : "";
var contactRequesterUrl = $(row).find("#capsule" + i + "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 = $(row).find("#duration_to_complete\\.tooltip--" + i);
jobData.duration = (durationToComplete.length) ? $(durationToComplete).closest("tr").find(".capsule_field_text").text().trim() : "";
jobData.durationParsed = getTimeLeft(jobData.duration);
var timeLeft = $(row).find("#time_left\\.tooltip--" + i);
jobData.timeLeft = (timeLeft.length) ? $(timeLeft).closest("tr").find(".capsule_field_text").text().trim() : "";
var hitsAvailable = $(row).find("#number_of_hits\\.tooltip--" + i);
jobData.hitsAvailable = (hitsAvailable.length) ? $(hitsAvailable).closest("tr").find(".capsule_field_text").text().trim() : "";
var rewardElement = $(row).find("#reward\\.tooltip--" + i);
jobData.pay = (rewardElement.length) ? $(rewardElement).closest("tr").find(".reward").text().replace("$","").trim() : "";
jobDatas.push(jobData);
}
});
return jobDatas;
}
function createHitRow(theData,buttons,fromWhere) {
var durationTime = (theData.duration != "Time") ? getTimeLeft(theData.duration) : theData.duration;
var durationText = (theData.duration != "Time") ? durationTime.hours + ":" + ("0" + durationTime.minutes).slice(-2) : theData.duration;
var payText = (theData.pay == "Pay") ? theData.pay : "$" + theData.pay;
var dialogWidth = $("#JREditDialog").width();
var titleWidth = (fromWhere=="pandas") ? 550 : 450;
var hitRow = createDiv().attr({"class":"hitRow"}).data("hitData",theData)
.append(createSpan(theData.requesterName).attr({"class":"aHitColumn"})
.css({"background-color":"#FBF5E6","width":"140px","text-align":"right","border":"1px solid black"}))
.append(createSpan(theData.title).attr({"class":"aHitColumn"})
.css({"background-color":"#FCF6CF","width":(dialogWidth - titleWidth) + "px","text-decoration":"underline","cursor":"pointer"})
.click( function(e) {
var thisData = $(e.target).closest(".hitRow").data("hitData");
var theHeight=window.outerHeight-80; var theWidth=window.outerWidth-10;
window.open(previewLink(thisData.groupId),"_blank","width=" + theWidth + ",height=" + theHeight + ",scrollbars=yes,toolbar=yes,menubar=yes,location=yes");
}))
.append(createSpan(durationText).attr({"class":"aHitColumn"}).css({"background-color":"#F5F5DC","width":"35px"}));
if (fromWhere=="mturk") hitRow.append(createSpan(theData.hitsAvailable).attr({"class":"aHitColumn"}).css({"background-color":"#F0FFFF","width":"40px"}));
hitRow.append(createSpan(payText).attr({"class":"aHitColumn"}).css({"background-color":"#7FFFD4","width":"40px"}));
if (buttons) hitRow.append(createSpanButton( function(e) {
var thisData = $(e.target).closest(".hitRow").data("hitData");
var newNumber = fillNewHitData(thisData.requesterName, thisData.requesterId, thisData.groupId, thisData.pay,
thisData.title, thisData.duration, false, true, true);
gMainData.hitCollection[newNumber].numberHits = thisData.hitsAvailable;
},"Panda",gButtonOffBgColor,gButtonOffColor,"10px").css({"white-space":"nowrap","overflow":"hidden","display":"inline-block"}))
.append(createSpanButton( function(e) {
var thisData = $(e.target).closest(".hitRow").data("hitData");
var newNumber = fillNewHitData(thisData.requesterName, thisData.requesterId, thisData.groupId, thisData.pay,
thisData.title, thisData.duration, true, true, true);
gMainData.hitCollection[newNumber].numberHits = thisData.hitsAvailable;
},"Once",gButtonOffBgColor,gButtonOffColor,"10px").css({"white-space":"nowrap","overflow":"hidden","display":"inline-block"}));
return hitRow;
}
function parseHitSearchPage(theResult,theNumber,searchWhere) {
var hitInfo = (theNumber>0) ? gMainData.hitCollection[theNumber] : null;
var hitData = (hitInfo) ? hitInfo.data : null;
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(theResult.responseText,"text/html");
var errorTitle_Array = xmlDoc.getElementsByClassName("error_title");
var errorTitle = (errorTitle_Array.length) ? errorTitle_Array[0] : null;
if (errorTitle && errorTitle.innerHTML.indexOf("You have exceeded the maximum allowed page request rate") != -1) {
processResults( theNumber, "TOOFAST" );
return;
} else if (errorTitle && errorTitle.innerHTML.indexOf("Your search did not match any HITs") != -1) {
if (theNumber<=0) {
$("#JREditDialog #searchingResultsArea").html("");
$("#JREditDialog #searchingResultsArea").append(createDiv("Nothing Found! Sorry.").css({"font-size":"25px","margin-top":"200px","text-align":"center"}));
gSavedSearchArea = "";
}
return;
} else {
var requestersInfo = doSortResultsTable(xmlDoc);
if (requestersInfo.length > 0) {
//console.log("JR HitsearchPage : I found some hits: " + requestersInfo.length);
var goUrl = "";
if (theNumber<=0) {
$("#JREditDialog #searchingResultsArea").html("");
var captions = {"requesterName":"Requester Name","title":"Hit Title","duration":"Time","hitsAvailable":"# Hits","pay":"Pay"};
var dialogWidth = $("#JREditDialog").width();
$("#JREditDialog #searchingResultsArea").append(createHitRow(captions,false,searchWhere));
$("#JREditDialog #searchingResultsArea").append(createDiv()
.css({"margin-left":"5px","background-color":"black","height":"6px","width":(dialogWidth - 145) + "px"}));
for (var ii=0, len1=requestersInfo.length; iiPausing.")
.css({"margin-top":"30px","font-size":"17px","text-align":"center","color":"red"})
.append(createDiv(createLink("Go to Mturk Page",hitInfo.pandaUrl,"_blank",hitInfo.pandaUrl)
.click( function(e) {
window.open($(e.target).attr("href"),"_blank","width=" + 1200 + ",height=" + 900 + ",scrollbars=yes,toolbar=yes,menubar=yes,location=yes");
return false;
})).css({"color":"blue","margin-top":"15px"}));
showWaitDialog("Captcha Alert!!","",function() {
theCycler.unpause();
$("#JRPauseButton").html("Pause").css({"background-color":"ivory","color":"black"});
},null,addText,true);
if (!theCycler.isPaused()) {
theCycler.pause();
$("#JRPauseButton").html("Resume").css({"background-color":"red","color":"white"});
playThisSound("hasToPause");
}
return;
}
var hitAccepted = $(xmlDoc).find("img[src$='/media/return_hit.gif']");
var notAccepted = $(xmlDoc).find("input[src$='/media/accept_hit.gif']");
if (errorTitle && errorTitle.innerHTML.indexOf("Your request was not completed successfully") != -1) {
processResults( theNumber, "NOTCOMPLETED" );
} else if (dailyLimit) {
processResults( theNumber, "DAILYLIMIT" );
} else if (hitAccepted.length) {
var updated = false;
var hitGroupId = ($(xmlDoc).find("form[name='hitForm']").length) ? $(xmlDoc).find("form[name='hitForm']").eq(0).find("input[name='groupId']").eq(0).val() : "";
hitData.groupId = hitGroupId;
hitInfo.pandaUrl = pandaLink(hitData.groupId);
hitInfo.previewUrl = previewLink(hitData.groupId);
hitInfo.hitId = ($(xmlDoc).find("form[name='hitForm']").length) ? $(xmlDoc).find("form[name='hitForm']").eq(0).find("input[name='hitId']").eq(0).val() : "";
var capsuleNode = $(xmlDoc).find("td.capsulelink_bold:first div").eq(0);
var theTitle = (capsuleNode.length) ? $(capsuleNode).html().trim() : hitData.title;
if (hitData.title != theTitle) { hitData.title = theTitle; updated=true; }
var timeLeft = $(xmlDoc).find("a#time_left\\.tooltip");
var theDuration = (timeLeft.length) ? timeLeft.parent().next().html().trim() : hitData.duration;
if (hitData.duration != theDuration) { hitData.duration = theDuration; updated=true; }
var requesterTip = $(xmlDoc).find("#requester\\.tooltip");
var requesterNameNode = (requesterTip.length) ? $(requesterTip).parent().next() : null;
var theRequesterName = (requesterNameNode.length) ? ( ($(requesterNameNode).find("a").length) ? $(requesterNameNode).find("a").html().trim() : $(requesterNameNode).html().trim() ) : "";
theRequesterName = (theRequesterName) ? theRequesterName : hitData.requesterName;
if (hitData.requesterName != theRequesterName) { hitData.requesterName = theRequesterName; updated=true; }
var numberHitsTip = $(xmlDoc).find("#number_of_hits\\.tooltip");
var theNumberHits = (numberHitsTip.length) ? numberHitsTip.parent().next().html().trim() : hitInfo.numberHits;
hitInfo.numberHits = theNumberHits;
var rewardTip = $(xmlDoc).find("#reward\\.tooltip");
var theReward = (rewardTip.length) ? rewardTip.parent().next().find("span").html().replace("$","").trim() : hitData.pay;
if (hitData.pay != theReward) { hitData.pay = theReward; updated=true; }
processResults( theNumber, "ACCEPTED" );
if (updated) gDelayedSave = true;
//console.log("accepted: " + theNumber + " | updated: " + updated + " | groupId: " + hitGroupId);
} else if (notAccepted.length) {
var formData = {};
formData.hitId = $(xmlDoc).find("input[name='hitId']").eq(0).val();
formData.prevHitSubmitted = $(xmlDoc).find("input[name='prevHitSubmitted']").eq(0).val();
formData.prevRequester = $(xmlDoc).find("input[name='prevRequester']").eq(0).val();
formData.requesterId = $(xmlDoc).find("input[name='requesterId']").eq(0).val();
formData.prevReward = $(xmlDoc).find("input[name='prevReward']").eq(0).val();
formData.groupId = $(xmlDoc).find("input[name='groupId']").eq(0).val();
formData.signature = $(xmlDoc).find("input[name='signature']").eq(0).val();
var iframeSrc = $(xmlDoc).find("iframe").attr("src");
var acceptHitURL = acceptLink(formData);
var useAcceptHit = false;
if (iframeSrc && formData.requesterId=="AGVV5AWLJY7H2") {
if (hitData.filterMode>0 && hitData.filterMode <= Object.keys(gZingFuncOptions).length) {
requestUrl(iframeSrc, theNumber, gZingFuncOptions[hitData.filterMode].functionName, errorRequest, formData, "");
} else { useAcceptHit = true;}
}
if (hitData.action.toLowerCase().indexOf("pantha")!=-1 || useAcceptHit) {
console.log("Pantha Mode is on or filter mode is on so need to accept after previewed.");
hitInfo.goToUrl.push({"url":acceptHitURL,"theNumber":theNumber});
theCycler.frontOfTheLine(theNumber);
}
} else { processResults( theNumber, "ERROR" ); }
}
function makeStatus() { return {"accepted":0,"skipped":0,"errors":0,"tooFast":0,"noHits":0,"fullQueue":0,"hitsStreak":0,
"noHitsStreak":0,"searched":0,"orphan":0,"hitsResults":0,"notQual":0,"missed":0}; }
function addHitCollection(theData,theNumber,tabIndex) {
var pandaUrl = pandaLink(theData.groupId);
var previewUrl = previewLink(theData.groupId);
var filterFuncData = (theData.action.toLowerCase().indexOf("filter") != -1) ? ((theData.requesterId=="AGVV5AWLJY7H2") ? gZingFuncOptions : null) : null;
gMainData.hitCollection[theNumber] =
{"collecting":"off","pandaUrl":pandaUrl,"previewUrl":previewUrl,"goToUrl":[],"theNumber":theNumber,"data":theData,"status":makeStatus(),"specialOptions":null,
"hitCell":null,"ham":"off","minutes":0,"newTitle":"","numberHits":"0","once":false,"filterFuncData":filterFuncData,"searching":"off","lastAccept":null,
"tabIndex":tabIndex,"hitId":"",durationParsed:null};
return theNumber;
}
function addQueueCheck() {
theCycler.addJob( function( elapsed, theNumber ) {
gMainData.queueStatus.searched++;
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) {
return parseQueuePage(theResult);
},function() { errorRequest(); } );
displayMainStatus();
return true;
}, -1, gMainOptions.queueTimer);
}
function startCollecting(theNumber,thisButton) {
var hitInfo = gMainData.hitCollection[theNumber];
var hitData = hitInfo.data;
if (hitData.once) hitData.dailyDone = 0;
hitInfo.collecting = "on";
//console.log("Turning on " + theNumber);
theCycler.addJob( function( elapsed, theNumber ) {
var hitInfo = gMainData.hitCollection[theNumber];
var hitData = hitInfo.data;
if (hitInfo.ham == "ontimed") {
if (hitData.hamTimer > 0 && hitInfo.lastAccept) {
var nowTime = new Date();
var elapsedTime = nowTime - hitInfo.lastAccept;
var theSeconds = elapsedTime / 1000;
var theMinutes = Math.floor(theSeconds / 60);
var offHamMode = (hitInfo.ham == "ontimed") ? "paused" : "off";
if (theSeconds >= hitData.hamTimer) {
toggleButton($("#JRHamB_" + theNumber),hamOn,hamOff,offHamMode);
hitInfo.lastAccept = null;
}
}
}
if ( checkLimits(theNumber) ) {
var theUrl = "";
var hitDataAction = hitData.action.toLowerCase();
hitInfo.status.searched++;
if (hitInfo.goToUrl.length) {
console.log("Found a gotoUrl so I must do Url");
if ( (hitDataAction.substring(0,6) == "search" || hitDataAction == "filterpanda" || hitDataAction == "pantha") && !hitInfo.hitCell.data("firstPanda") )
theUrl = (hitInfo.goToUrl.shift()).url;
else theUrl = (hitInfo.goToUrl[0]).url;
} else {
theUrl = ( hitDataAction == "panda" ) ? hitInfo.pandaUrl : (hitDataAction.substring(0,6) == "search") ?
requesterSearch(hitData.requesterId) : hitInfo.previewUrl;
}
gMainData.searched++;
gMainData.lastElapsed = elapsed;
//console.log("Doing Number: " + theNumber + " | going to: " + theUrl);
if (theUrl.indexOf("selectedSearchType=hitgroups")!=-1) requestUrl(theUrl,theNumber,parseHitSearchPage,
errorRequest, hitInfo.status.searched, "");
else requestUrl(theUrl,theNumber,parseMturkHitPage, errorRequest, hitInfo.status.searched, "");
displayHitStatus(theNumber);
return true;
} else if (gScriptStatus == "normal") {
$("#JRCellNum_" + theNumber).stop(true,true);
$("#JRCellNum_" + theNumber).css({"background-color":"#FF9999"});
$("#JRCellNum_" + theNumber).animate({backgroundColor: $("#JRCellNum_" + theNumber).data("backgroundColor")}, 40000);
return false;
}
}, theNumber, 0);
gMainData.jobs++;
//addQueueCheck();
}
function stopCollecting(theNumber,thisButton) {
//console.log("turning off " + theNumber);
if (gMainData.hitCollection[theNumber].collecting == "on") {
gMainData.hitCollection[theNumber].collecting = "off";
gMainData.hitCollection[theNumber].goToUrl.splice(0,gMainData.hitCollection[theNumber].goToUrl.length);
theCycler.removeJob(theNumber);
gMainData.jobs--;
}
displayHitStatus(theNumber);
}
function stopAll() {
$.each(gMainData.hitCollection, function( index, value ) {
if (value.collecting == "on") {
toggleButton( $("#JRCollectB_" + index),startCollecting,stopCollecting);
if (value.collecting=="off" && value.ham != "off") toggleButtonOff($("#JRHamB_" + index),hamOn,hamOff);
}
});
}
function hamOn(theNumber,thisButton) {
var onMode = "on";
$(".JRHamButton").each( function() {
if ( $(this).data("theNumber") != theNumber ) $(this).data("disabled",true);
updateHitColors($(this).data("theNumber"));
});
if (gMainData.hitCollection[theNumber].ham == "paused") onMode = "ontimed";
gMainData.hitCollection[theNumber].ham = onMode;
theCycler.hamOn(theNumber);
theCycler.skippingReset();
theCycler.cycleResetChange(gMainOptions.HamCycleNumber);
}
function hamOff(theNumber,thisButton,theMode) {
var passedMode = theMode || "";
var hitInfo = gMainData.hitCollection[theNumber];
if (hitInfo.ham.substring(0,2) == "on") {
$(".JRHamButton").each( function() {
if ( $(this).data("disabled") ) $(this).data("disabled",false);
updateHitColors($(this).data("theNumber"));
});
cycleButtonSelect(gMainOptions.savedCycleNum)
theCycler.hamOff();
theCycler.skippingReset();
}
if (passedMode === "" && hitInfo.ham == "ontimed" && hitInfo.collecting != "off") passedMode = "paused";
gMainData.hitCollection[theNumber].ham = (passedMode==="") ? "off" : passedMode;
$("#JRCellNum_" + theNumber).data("firstPanda",false);
}
function muteJob(theNumber) {
var hitInfo = gMainData.hitCollection[theNumber];
hitInfo.data.mute = !hitInfo.data.mute;
hitInfo.hitCell.data("mute",hitInfo.data.mute);
updateHitColors( theNumber );
saveSettings();
}
function helpToolTips() {
if (gMainOptions.showHelpTooltips) $(".hasHelptip").tooltip( "option", "disabled", false );
else $(".hasHelptip:not(.keepHelptip)").tooltip( "option", "disabled", true );
}
function addTab(tabContainer,theTitle,isSortable,theID,tabData,appendClose) {
var theTab = createTab(tabContainer,theTitle,isSortable,theID,tabData,appendClose)
.data({"tabData":tabData});
createDiv().insertBefore(theTab.find("br.cleartab"))
.data({"tabData":tabData})
.attr({"class":"tabContents connectedSortable"})
.css({"overflow":"auto"})
.sortable({dropOnEmpty: true,delay:400,connectWith: ".connectedSortable",tolerance: "pointer","items":".JRHitCell:not(.ui-not-sortable)",
helper:"clone",opacity: 0.9,appendTo:"body",
start: function( event, ui ) {
//$(".hasTooltip").tooltip("disable");
ui.item.addClass('noclick');
ui.item.data("oldPosition",ui.item.index());
ui.item.data("received",false);
},
receive: function( event, ui ) {
ui.item.data("received",true);
$(event.target).find(".JRHitDummy").remove();
gTabsData[ui.item.data("hitInfo").tabIndex].positions.splice(ui.item.data("oldPosition"), 1);
$(event.target).data("tabData").positions.splice(ui.item.index(), 0, ui.item.data("theNumber"));
ui.item.data("hitInfo").tabIndex = $(gTabsData).index($(event.target).data("tabData"));
ui.item.data("hitData").tabNumber = $(event.target).data("tabData").tabNumber;
$(event.target).append(createDiv(" ").attr("class","JRHitCell JRHitDummy").data("hitInfo",{"tabIndex":0})
.css({"border":"3px solid transparent", "margin":"2px 4px", "float":"left", "width":"206px", "height":"76px"}));
saveSettings();
},
stop: function( event, ui ) {
if (ui.item.data("hitInfo") && !ui.item.data("received")) {
$(event.target).find(".JRHitDummy").remove();
var thePositions = gTabsData[ui.item.data("hitInfo").tabIndex].positions;
thePositions.splice(ui.item.index(), 0, thePositions.splice(ui.item.data("oldPosition"), 1)[0]);
$(event.target).append(createDiv(" ").attr("class","JRHitCell JRHitDummy").data("hitInfo",{"tabIndex":0})
.css({"border":"3px solid transparent", "margin":"2px 4px", "float":"left", "width":"206px", "height":"76px"}));
saveSettings();
}
$(".hasTooltip").tooltip("enable");
}
});
return theTab;
}
function fillNewHitData(requesterName, requesterId, groupId, pay, title, duration, onlyOnce, toMain, collectNow) {
var active = (toMain) ? 0 : $( "#JRMainTabs" ).tabs( "option", "active" );
var newHitData = jQuery.extend(true, {}, gRequestersData[0]);
newHitData.action = "panda"; newHitData.qual = ""; newHitData.queueLimit = 0; newHitData.audioforce = ""; newHitData.hitlimit = ""; newHitData.mute = false;
newHitData.position = null; newHitData.tabNumber = gTabsData[active].tabNumber; newHitData.hamTimer = gMainOptions.hamDelayTimer; newHitData.once = onlyOnce;
newHitData.requesterName = (requesterName) || ""; newHitData.requesterId = (requesterId) || ""; newHitData.groupId = groupId;
newHitData.pay = (pay) || "0.00"; newHitData.title = (title) || groupId; newHitData.duration = (duration) || "";
var newCell = addHitData(newHitData,active);
if (collectNow) {
newCell.data("status","on");
toggleButton( newCell.find(".JRCollectButton"),startCollecting,stopCollecting );
}
if (theCycler.isHamOn()) newCell.find(".JRHamButton").data("disabled",true);
updateHitCell(newCell.data("theNumber"));
updateHitColors(newCell.data("theNumber"));
return newCell.data("theNumber");
}
function changeToEdited() { $("#JREditDialog").data("edited",true); $("div[aria-describedby='JREditDialog'] .ui-dialog-buttonpane button:contains('Save')").button().show(); }
function dataEdited(thisArea,theValue) {
changeToEdited();
var inputEdit = createTextInput(theValue).css({"width":"300px"});
if ($(thisArea).data("doClick")) $(inputEdit).click( function(e) { $(thisArea).data("doClick")(e); });
$(inputEdit).focus( function(e) {
if ($(thisArea).data("doFocus") && !$(thisArea).data("focusOff")) $(thisArea).data("doFocus")(e);
$(e.target).select();
});
$(thisArea).find("span:not(.errorEditLine):not(.defaultEdit)").replaceWith(inputEdit);
$(inputEdit).focus();
}
function dataTrueFalse(thisArea,theValue) {
changeToEdited();
if (theValue) returnValue=false;
else returnValue=true;
$(thisArea).find("span").html(returnValue.toString());
return returnValue;
}
function dataRadioButtons(theName,theValues,theValue,theChangeFunction) {
changeToEdited();
var radioButtons = createSpan().data("changeFunction",theChangeFunction);
$.each(theValues, function(index, value) {
var valueID = value.toLowerCase();
var aRadio = createRadioButton(theName,valueID).attr({"id":valueID + "_radio_" + index}).css({"width":"20px"});
if (valueID == theValue) aRadio.prop("checked",true);
else aRadio.prop("checked",false);
createSpan().append(aRadio).append($("