JR Mturk Panda Crazy Helper

A script add on for Panda Crazy sending commands to main script.

  1. // ==UserScript==
  2. // @name JR Mturk Panda Crazy Helper
  3. // @version 0.3.15
  4. // @namespace https://gf.qytechs.cn/users/6406
  5. // @description A script add on for Panda Crazy sending commands to main script.
  6. // @author (JohnnyRS on mturkcrowd.com and mturkgrind.com) johnnyrs@allbyjohn.com
  7. // @include http*://worker.mturk.com/*
  8. // @include http*://*mturkcrowd.com/threads/*
  9. // @include http*://*turkerview.com/threads/*
  10. // @include http*://*mturkforum.com/showthread*
  11. // @include http*://*mturkforum.com/*threads/*
  12. // @include http*://*hitnotifier.com/*
  13. // @include http*://www.reddit.com/r/HITsWorthTurkingFor*
  14. // @exclude http*://*mturk.com/mturk/findhits?*hit_scraper*
  15. // @require http://code.jquery.com/jquery-2.1.4.min.js
  16. // @grant GM_getValue
  17. // @grant GM_setValue
  18. // @grant GM_deleteValue
  19. // ==/UserScript==
  20.  
  21. var gScriptVersion = "0.3.15";
  22. var gScriptName = "pandacrazy";
  23. var gLocation = window.location.href, gNewSite=false, gHitNotifier;
  24. var gConstantSearch = null;
  25. var gJobDataDefault = {"requesterName":"","requesterId":"","groupId":"","pay":"","title":"","duration":"0","hitsAvailable":0,"timeLeft":"","totalSeconds":0,"hitId":"",
  26. "qual":"","continueURL":"","returnURL":"","durationParsed":{},"jobNumber":"-1","friendlyRName":"","friendlyTitle":"","assignedOn":"","description":"",
  27. "keywords":"","timeData":{},"assignmentID":"","hitSetID":"","secondsOff":-1,"goHam":false};
  28.  
  29. function createMessageData(command,data) { return {"time":(new Date().getTime()),"command":command,"data":data}; }
  30. function sendCommandMessage(data) { localStorage.setItem("JR_message_" + gScriptName, JSON.stringify(data)); }
  31. function createQueueData(length) { return {"queueLength":length}; }
  32. function createProjectedData(earnings) { return {"projectedEarnings":earnings}; }
  33. function createJobData(jobData) { return {"groupId":jobData.groupId,"title":jobData.title,"requesterName":jobData.requesterName,"requesterId":jobData.requesterId,
  34. "pay":jobData.pay,"duration":jobData.duration,"hitsAvailable":jobData.hitsAvailable}; }
  35. function setAttributes(el, attrs) { for (var key in attrs) { el.setAttribute(key, attrs[key]); } }
  36. function elementInit(theElement,theClass,theText,theStyle) {
  37. if (theClass) theElement.className = theClass; if (theText) theElement.textContent = theText; if (theStyle) theElement.style = theStyle; return theElement;
  38. }
  39. function createSpan(theClass,theText,theStyle) { var span = document.createElement("span"); return elementInit(span,theClass,theText,theStyle); }
  40. function createSpanButton(toDo,theClass,theText,theBackgroundColor,theColor,theFontSize,addStyle) {
  41. var backgroundColor = (typeof theBackgroundColor != 'undefined') ? theBackgroundColor : "initial";
  42. var textColor = (typeof theColor != 'undefined') ? theColor : "initial", fontSize = (typeof theFontSize != 'undefined') ? theFontSize : "9px";
  43. var theButton = createSpan("nonselectable " + theClass,theText,"font-size:" + fontSize + "; padding:0px 2px; background-color:" + backgroundColor + "; color:" + textColor +
  44. "; border:2px groove darkgrey; cursor:default; margin:0px 1px;" + addStyle);
  45. if (toDo) theButton.addEventListener("click", function (e) { toDo(e); });
  46. return theButton;
  47. }
  48. function speakThisNow(thisText) {
  49. if('speechSynthesis' in window){
  50. var speech = new SpeechSynthesisUtterance(thisText);
  51. speech.lang = 'en-US';
  52. window.speechSynthesis.speak(speech);
  53. }
  54. }
  55. function locationForums() {
  56. if (gLocation.match(/.*(mturkcrowd|turkerview|mturkforum|reddit)\.com.*/)!==null) return true;
  57. else return false;
  58. }
  59. function getTimeLeft(theTime) {
  60. if (theTime!==null && theTime!=="") {
  61. var tempArray = (theTime.indexOf("second") != -1) ? theTime.split("second")[0].trim().split(" ") : null;
  62. var seconds = (tempArray) ? parseInt(tempArray[tempArray.length-1]) : 0;
  63. tempArray = (theTime.indexOf("minute") != -1) ? theTime.split("minute")[0].trim().split(" ") : null;
  64. var minutes = (tempArray) ? parseInt(tempArray[tempArray.length-1]) : 0;
  65. tempArray = (theTime.indexOf("hour") != -1) ? theTime.split("hour")[0].trim().split(" ") : null;
  66. var hours = (tempArray) ? parseInt(tempArray[tempArray.length-1]) : 0;
  67. tempArray = (theTime.indexOf("day") != -1) ? theTime.split("day")[0].trim().split(" ") : null;
  68. var days = (tempArray) ? parseInt(tempArray[tempArray.length-1]) : 0;
  69. tempArray = (theTime.indexOf("week") != -1) ? theTime.split("week")[0].trim().split(" ") : null;
  70. var weeks = (tempArray) ? parseInt(tempArray[tempArray.length-1]) : 0;
  71. return( {"weeks":weeks,"days":days,"hours":hours,"minutes":minutes,"seconds":seconds} );
  72. } else return null;
  73. }
  74. function formatTimeLeft(resetNow,thisDigit,timeString,lastDigit) {
  75. formatTimeLeft.timeFill = formatTimeLeft.timeFill || 0;
  76. if (resetNow) formatTimeLeft.timeFill = 0;
  77. var missingDigit = (lastDigit!="0" && thisDigit=="0") ? true : false;
  78. if (( thisDigit!="0" || missingDigit) && formatTimeLeft.timeFill<2) {
  79. formatTimeLeft.timeFill++;
  80. if (missingDigit) { return "00 " + timeString + "s"; }
  81. else {
  82. var addZero = (thisDigit<10) ? ((formatTimeLeft.timeFill==1) ? false : true) : false, plural = (thisDigit==1) ? false : true;
  83. return ((addZero) ? "0" : "") + thisDigit + " " + ((plural) ? (timeString+"s") : timeString) + " ";
  84. }
  85. } else return "";
  86. }
  87. function convertToTimeString(timeData) {
  88. var returnString = "";
  89. returnString += formatTimeLeft(true,timeData.weeks,"week",false); returnString += formatTimeLeft(false,timeData.days,"day",timeData.weeks);
  90. returnString += formatTimeLeft(false,timeData.hours,"hour",timeData.days); returnString += formatTimeLeft(false,timeData.minutes,"minute",timeData.hours);
  91. returnString += formatTimeLeft(false,timeData.seconds,"second",timeData.minutes);
  92. return returnString.trim();
  93. }
  94. function convertTimeToSeconds(timeData) {
  95. var totalSeconds = timeData.seconds + ((timeData.minutes) ? (timeData.minutes*60) : 0) + ((timeData.hours) ? (timeData.hours*3600) : 0) +
  96. ((timeData.days) ? (timeData.days*86400) : 0) + ((timeData.weeks) ? (timeData.weeks*604800) : 0);
  97. return totalSeconds;
  98. }
  99. function convertSecondsToTimeData(seconds) {
  100. var timeData = {};
  101. timeData.weeks = Math.floor(seconds/604800); seconds = seconds - (timeData.weeks*604800);
  102. timeData.days = Math.floor(seconds/86400); seconds = seconds - (timeData.days*86400);
  103. timeData.hours = Math.floor(seconds/3600); seconds = seconds - (timeData.hours*3600);
  104. timeData.minutes = Math.floor(seconds/60); seconds = seconds - (timeData.minutes*60);
  105. timeData.seconds = seconds;
  106. return timeData;
  107. }
  108. function convertToSeconds(milliseconds,fixed) { fixed = fixed || 2; var seconds = parseFloat((milliseconds/1000.0 * 100) / 100).toFixed(fixed) + ""; return seconds.replace(/\.0*$/,""); }
  109. function convertToMilliseconds(seconds) { if (seconds) return seconds*1000 + ""; else return "0"; }
  110.  
  111. function sendMessageData(command,theData) {
  112. var messageData = createMessageData(command,theData);
  113. sendCommandMessage(messageData);
  114. }
  115. function sendQueueData(queueLength) { sendMessageData("queueData",createQueueData(queueLength)); }
  116. function sendProjectedData(projectedEarnings) { sendMessageData("projectedEarnings",createProjectedData(projectedEarnings)); }
  117. function sendJobData(jobData) { sendMessageData("addJob",createJobData(jobData)); }
  118. function sendJobOnceData(jobData) { sendMessageData("addOnceJob",createJobData(jobData)); }
  119. function sendJobSearchData(jobData) { sendMessageData("addSearchJob",createJobData(jobData)); }
  120. function sendPingMessage() { localStorage.setItem("JR_message_ping_" + gScriptName, JSON.stringify({"command":"areYouThere","time":(new Date().getTime())})); }
  121.  
  122. function appendPandaButtons(element,jobData) {
  123. $(element).append($("<span>").css({"font-size":"9px"}).html("Add: ")
  124. .append($("<button>").html("Panda").css({"font-size":"10px","line-height":"10px","padding":"1px","color":"black"})
  125. .data("jobData",jobData).attr({"type":"button"})
  126. .click(function(e) { sendJobData($(e.target).data("jobData")); return false; }))
  127. .append($("<button>").html("Once").css({"font-size":"10px","line-height":"10px","padding":"1px","color":"black"})
  128. .data("jobData",jobData).attr({"type":"button"})
  129. .click(function(e) { sendJobOnceData($(e.target).data("jobData")); return false; }))
  130. .append($("<button>").html("Search").css({"font-size":"10px","line-height":"10px","padding":"1px","color":"black"})
  131. .data("jobData",jobData).attr({"type":"button"})
  132. .click(function(e) { sendJobSearchData($(e.target).data("jobData")); return false; }))
  133. );
  134. }
  135. function parseHitsInfo(reactInfo,finalUrl) {
  136. var jobData = jQuery.extend(true, {}, gJobDataDefault), projectData = ("project" in reactInfo) ? reactInfo.project : reactInfo;
  137. jobData.hitSetID = projectData.hit_set_id; jobData.hitsAvailable = projectData.assignable_hits_count;
  138. jobData.continueURL = ""; jobData.returnURL = ""; jobData.groupId = projectData.hit_set_id;
  139. jobData.requesterName = projectData.requester_name; jobData.requesterId = projectData.requester_id;
  140. jobData.totalSeconds = projectData.assignment_duration_in_seconds; jobData.timeData = convertSecondsToTimeData(jobData.totalSeconds);
  141. jobData.title = projectData.title; jobData.timeLeft = convertToTimeString(jobData.timeData);
  142. jobData.pay = parseFloat(projectData.monetary_reward.amount_in_dollars).toFixed(2);
  143. jobData.duration = jobData.timeLeft;
  144. return jobData;
  145. }
  146. function parseNewHitPageRequesters(projectDetailBar,finalUrl) {
  147. var jobData = jQuery.extend(true, {}, gJobDataDefault);
  148. var tempPrevDiv = projectDetailBar[0].getElementsByClassName("col-sm-4 col-xs-5");
  149. if (tempPrevDiv.length===0) tempPrevDiv = projectDetailBar[0].getElementsByClassName("col-md-6 col-xs-12"); // col-md-6 col-xs-12
  150. if (tempPrevDiv.length===0) tempPrevDiv = projectDetailBar[0].getElementsByClassName("col-xs-12"); // col-xs-12
  151. if (tempPrevDiv.length===0) tempPrevDiv = projectDetailBar[0].getElementsByClassName("p-l-xs");
  152. var reactInfo = (tempPrevDiv.length>0) ? tempPrevDiv[0].firstElementChild.dataset.reactProps : null;
  153. if (reactInfo) {
  154. reactInfo = JSON.parse(reactInfo).modalOptions;
  155. var contactRequesterUrl = reactInfo.contactRequesterUrl, contactVar = (contactRequesterUrl.indexOf("requester_id") != -1) ? "requester_id%5D=" : "requesterId=";
  156. jobData.hitsAvailable = reactInfo.assignableHitsCount; jobData.requesterName = reactInfo.requesterName;
  157. jobData.groupId = finalUrl.split("/projects/")[1].split("/")[0]; jobData.hitSetID = jobData.groupId;
  158. if (finalUrl.indexOf("assignment_id")!=-1) {
  159. jobData.hitId = finalUrl.split("/tasks/")[1].split("?")[0]; jobData.assignmentId = finalUrl.split("assignment_id=")[1].split("&")[0];
  160. jobData.continueURL = finalUrl;
  161. } else { jobData.hitId = ""; jobData.assignmentId = ""; jobData.continueURL = ""; }
  162. jobData.returnURL = "";
  163. var tempContact = contactRequesterUrl.split(contactVar); if (tempContact.length) jobData.requesterId = contactRequesterUrl.split(contactVar)[1].split("&")[0];
  164. jobData.totalSeconds = reactInfo.assignmentDurationInSeconds; jobData.timeData = convertSecondsToTimeData(jobData.totalSeconds); jobData.title = reactInfo.projectTitle;
  165. jobData.timeLeft = convertToTimeString(jobData.timeData); jobData.pay = parseFloat(reactInfo.monetaryReward.amountInDollars).toFixed(2);
  166. jobData.duration = jobData.timeLeft;
  167. }
  168. return jobData;
  169. }
  170. function findProjectedEarnings() {
  171. // find if Projected Earnings scripts are installed and get info.
  172. var spanEarnings = null, earnings = "";
  173. if ( ($(".me-bar").length ) ) {
  174. spanEarnings = $(".me-bar:first").find("span:contains('Earnings:'):first");
  175. if (spanEarnings) earnings = $(spanEarnings).next("a").text();
  176. sendProjectedData(earnings.replace("$",""));
  177. }
  178. }
  179. function pcContainer(thisGroupId,thisRequesterName,thisRequesterId,thisTitle,thisReward) {
  180. var thisContainer = $(createSpan("PCSpanButtons","","")).append(document.createTextNode(" [PC] Add: "))
  181. .append($(createSpanButton(function(e) { window.open("https://worker.mturk.com/requesters/PandaCrazyAdd/projects?JRGID=" + thisGroupId + "&JRRName=" +
  182. thisRequesterName + "&JRRID=" + thisRequesterId + "&JRTitle=" + thisTitle + "&JRReward=" + thisReward,
  183. "PandaCommand", "height=200,width=200"); },"","Panda", "lightgrey","red","11px")))
  184. .append($(createSpanButton(function(e) { window.open("https://worker.mturk.com/requesters/PandaCrazyOnce/projects?JRGID=" + thisGroupId + "&JRRName=" +
  185. thisRequesterName + "&JRRID=" + thisRequesterId + "&JRTitle=" + thisTitle + "&JRReward=" + thisReward,
  186. "PandaCommand", "height=200,width=200"); },"","Once", "lightgrey","red","11px")))
  187. .append($(createSpanButton(function(e) { window.open("https://worker.mturk.com/requesters/PandaCrazySearch/projects?JRGID=" + thisGroupId + "&JRRName=" +
  188. thisRequesterName + "&JRRID=" + thisRequesterId + "&JRTitle=" + thisTitle + "&JRReward=" + thisReward,
  189. "PandaCommand", "height=200,width=200"); },"","Search", "lightgrey","red","11px")));
  190. return thisContainer;
  191. }
  192. function format1(foundUrl,thisNode) {
  193. var thisGroupId="", thisRequesterName="", thisRequesterId="", thisTitle="", thisReward="";
  194. var grabbedUrl = foundUrl.attr("href"); var newWorkerSite = (grabbedUrl.indexOf("worker.mturk.com") != -1) ? true : false;
  195. if (newWorkerSite) thisGroupId = grabbedUrl.split("/projects/")[1].split("/tasks")[0];
  196. else thisGroupId = grabbedUrl.split("groupId=")[1].split("&")[0];
  197. thisRequesterName = escape($(thisNode).find("b:contains('Requester:')").next("a").text().trim());
  198. thisRequesterId = ($(thisNode).find("b:contains('Requester:')").next("a")).attr("href").split("/requesters/")[1].split("/projects")[0];
  199. thisRequesterId = thisRequesterId.split("]")[0].replace("[","").replace("]","");
  200. var bTitle = $(thisNode).find("b:contains('Title:')");
  201. thisTitle = escape($(thisNode).find("b:contains('Title:')").next("a").text().trim());
  202. thisReward = escape($(thisNode).find("b:contains('Reward:')").next("span, font").text().trim().replace("$",""));
  203. if (thisReward==="") thisReward = escape($(thisNode).find("b:contains('Reward:')").get(0).nextSibling.nodeValue.trim().replace("$",""));
  204. return {"GID":thisGroupId,"RID":thisRequesterId,"RName":thisRequesterName,"Title":thisTitle,"Reward":thisReward};
  205. }
  206. function format2(foundUrl,thisNode) {
  207. var thisGroupId="", thisRequesterName="", thisRequesterId="", thisTitle="", thisReward="", thisRequesters = null, thisTitleRaw = null;
  208. var requesterIdRegex2 = /mturk\.com\/requesters\/([^\/^\n\s]*)/, rewardTitleRegex = /(.+) - \$*(\d+\.\d\d)(.*)$/, groupIdRegex = /mturk\.com\/projects\/([^\/]*)\/tasks/;
  209. thisGroupId = groupIdRegex.exec($(foundUrl).attr("href"))[1];
  210. thisRequesters = $(thisNode).find("a[href*='mturk.com/requesters']:first");
  211. thisRequesterName = unescape($(thisRequesters).text().trim());
  212. thisRequesterId = requesterIdRegex2.exec($(thisRequesters).attr("href"))[1];
  213. thisTitleRaw = rewardTitleRegex.exec($(thisNode).find("i").text().trim());
  214. thisTitle = (thisTitleRaw) ? thisTitleRaw[1] : "Unknown Title";
  215. thisReward = (thisTitleRaw) ? thisTitleRaw[2] : "-.--";
  216. return {"GID":thisGroupId,"RID":thisRequesterId,"RName":thisRequesterName,"Title":thisTitle,"Reward":thisReward};
  217. }
  218. function format3(foundUrl,thisNode) {
  219. var thisGroupId="", thisRequesterName="", thisRequesterId="", thisTitle="", thisReward="", thisRequester=null;
  220. var requesterUrl = $(thisNode).find("a[href*='/requesters/']").attr("href"), thisText = $(thisNode).text();
  221. var rewardRegex = /Reward: *\$*(\d+\.\d\d)/, titleRegex = /Title: *([^•\n]*)(\| panda|\| accept|• )/i, groupIdRegex = /mturk\.com\/projects\/([^\/]*)\/tasks/;
  222. var requesterNameRegex = /Requester: *([^•\n]*)(\[[A-Z0-9]+\]|\| Panda|•)/, requesterNameRegex2 = /Requester: *([^\n]+)/;
  223. var requesterIdRegex = /turkerview\.com\/requesters\/([^\/^\n\s]*)/, requesterIdRegex2 = /mturk\.com\/requesters\/([^\/^\n\s]*)/;
  224. thisGroupId = groupIdRegex.exec($(foundUrl).attr("href"))[1];
  225. thisRequester = requesterNameRegex.exec(thisText);
  226. thisRequesterName = (thisRequester) ? thisRequester[1] : requesterNameRegex2.exec(thisText)[1];
  227. thisRequesterId = (thisRequester) ? thisRequester[2] : "--";
  228. if (thisRequesterId=="--") thisRequesterId = requesterIdRegex2.exec(requesterUrl)[1];
  229. if (thisRequesterId=="•") thisRequesterId = requesterIdRegex.exec(thisText)[1];
  230. else thisRequesterId = thisRequesterId.replace(/[\[\]]/g,"");
  231. thisTitle = titleRegex.exec(thisText)[1];
  232. thisReward = rewardRegex.exec(thisText)[1];
  233. return {"GID":thisGroupId,"RID":thisRequesterId,"RName":thisRequesterName,"Title":thisTitle,"Reward":thisReward};
  234. }
  235. function addMessageButtons(thisMessage) {
  236. var myContainer=null, thisGroupId="", thisRequesterName="", thisRequesterId="", thisTitle="", thisReward="", jobData = null;
  237. var firstNode = $(thisMessage).find(".ctaBbcodeTableRowTransparent, table.cms_table");
  238. if (gLocation.indexOf("mturkforum.com") != -1) firstNode = $(thisMessage).find("table");
  239. if (firstNode.length) {
  240. $(firstNode).each( function() {
  241. var theAcceptUrl = $(this).find("a:contains('Accept')"), format=1, grabbedUrl = "";
  242. if (!theAcceptUrl.length) { format=2; theAcceptUrl = $(this).find("a:contains('PANDA')"); }
  243. if (theAcceptUrl.length) {
  244. jobData = (format==1) ? format1(theAcceptUrl,this) : format2(theAcceptUrl,this);
  245. myContainer = pcContainer(jobData.GID,jobData.RName,jobData.RID,jobData.Title,jobData.Reward);
  246. var newWorkerSite = ($(theAcceptUrl).attr("href").indexOf("worker.mturk.com") != -1) ? true : false;
  247. var contactLinkFound = ($(this).find("a:contains('Contact')").length) ? true : false;
  248. var requesterLinkFound = ($(this).find("a:contains('Requester')").length) ? true : false;
  249. if ($(this).find("a:contains('Req TV')").length) $(this).find("a:contains('Req TV'):first").next("b").after($(myContainer));
  250. else if ($(this).find("a[href*='turkerview.com/requesters/']").length) $(this).find("a:contains('Contact'):first").after($(myContainer));
  251. else if (requesterLinkFound) $(this).find("a:contains('Requester'):first").after($(myContainer));
  252. else if (contactLinkFound && newWorkerSite && format==1) $(this).find("a:contains('Contact'):first").after($(myContainer));
  253. else if (contactLinkFound && $(this).find("a[href*='turkopticon']").length) $(this).find("a[href*='turkopticon']:first").prev().before($(myContainer));
  254. else if ($(this).find("b:contains('TO Ratings:')").length) $(this).find("b:contains('TO Ratings:')").prev("br").before($(myContainer));
  255. }
  256. });
  257. } else if ($(thisMessage).find(".vw-div:first").length) {
  258. var vwDiv = $(thisMessage).find(".vw-div:first");
  259. if (vwDiv.length && $(thisMessage).find("a:contains('PANDA')").length) {
  260. jobData = format2($(thisMessage).find("a:contains('PANDA')"),thisMessage);
  261. myContainer = pcContainer(jobData.GID,jobData.RName,jobData.RID,jobData.Title,jobData.Reward);
  262. $(vwDiv).prev().after(myContainer);
  263. }
  264. } else if ($(thisMessage).find("a[href*='/r/HITsWorthTurkingFor/']").length) {
  265. // reserved for reddit
  266. } else if ($(thisMessage).find("a[href*='turkerview.com/requesters/']").length || $(thisMessage).find("b:contains('TurkerView:')").length ||
  267. $(thisMessage).find("a[href*='turkopticon']").length ) {
  268. var thisOne = $(thisMessage);
  269. if ($(thisMessage).find(".quoteContainer").length) thisOne = $(thisMessage).find(".quoteContainer");
  270. else if ($(thisMessage).find(".bbTable").length) thisOne = $(thisMessage).find(".bbTable");
  271. jobData = format3($(thisOne).find("a[href*='mturk.com/projects/']:first"),thisOne);
  272. myContainer = pcContainer(jobData.GID,jobData.RName,jobData.RID,jobData.Title,jobData.Reward);
  273. if ($(thisOne).find("a:contains('AcceptA')").length) $(thisOne).find("a:contains('AcceptA')").after(myContainer);
  274. else if ($(thisOne).find("a:contains('Accept')").length) $(thisOne).find("a:contains('Accept')").after(myContainer);
  275. else if ($(thisOne).find("a:contains('PANDA')").length) $(thisOne).find("a:contains('PANDA')").after(myContainer);
  276. else $(thisOne).find("a[href*='mturk.com/requesters']:first").after(myContainer);
  277. }
  278. $(thisMessage).addClass("JRDoneButtonized");
  279. }
  280. function addPageButtons() {
  281. $("blockquote:not('.quoteContainer, .JRDoneButtonized, .bbCodeBlock'), .card:not('.col-10'), #hit, .bbWrapper, #siteTable [data-context='comments']").each( function() {
  282. addMessageButtons(this);
  283. });
  284. }
  285.  
  286. function mainListener(e) {
  287. if ( e.key == 'JR_message_pong_' + gScriptName && e.newValue && gLocation == (JSON.parse(e.newValue).url)) {
  288. window.removeEventListener("storage", mainListener, false);
  289. var noHitsError = ($("td.error_title:contains('There are currently no HITs assigned to you.')").length > 0), buttonPosition=null;
  290. var noHitsAlert = ($("#alertboxHeader:contains('There are currently no HITs assigned to you.')").length > 0);
  291. var returnedAlert = ($("#alertboxHeader:contains('The HIT has been returned.')").length > 0);
  292. if ( gLocation.indexOf("worker.mturk.com") != -1 ) {
  293. var projectDetailBar = $(".project-detail-bar"), requestersInfo={};
  294. var mturkAlertDanger = $(".mturk-alert-danger");
  295. if (mturkAlertDanger.length && $(mturkAlertDanger).find(".mturk-alert-content:contains('There are no more of these HITs available')")) {
  296. var savedGID = GM_getValue("JRHoldGID"), savedRID = GM_getValue("JRHoldRID"), savedRName = GM_getValue("JRHoldRName"),
  297. savedTitle = GM_getValue("JRHoldTitle"), savedReward = GM_getValue("JRHoldReward");
  298. if (savedGID && savedGID!=="" &&
  299. $("button:contains('Accept'), button:contains('Return'), .mturk-alert-content:contains('This HIT requires Qualifications')").length === 0) {
  300. $(mturkAlertDanger).find(".p-b-0").append($("<span>").attr({"class":"JR_PandaCrazy"}).css({"font-size":"10px","margin-left":"10px"}).html("[PC] "));
  301. var thisJobData = jQuery.extend(true, {}, gJobDataDefault);
  302. thisJobData.groupId = savedGID; thisJobData.requesterId = savedRID || ""; thisJobData.requesterName = savedRName || "";
  303. thisJobData.title = savedTitle || ""; thisJobData.pay = savedReward || "";
  304. appendPandaButtons($(mturkAlertDanger).find(".JR_PandaCrazy:first"),thisJobData);
  305. }
  306. }
  307. GM_deleteValue("JRHoldGID"); GM_deleteValue("JRHoldRID"); GM_deleteValue("JRHoldRName"); GM_deleteValue("JRHoldTitle"); GM_deleteValue("JRHoldReward");
  308. if (projectDetailBar.length) {
  309. requestersInfo = parseNewHitPageRequesters(projectDetailBar,gLocation);
  310. buttonPosition = $(".task-project-title:first").parent().parent().parent();
  311. $(buttonPosition).append($("<span>").attr({"class":"JR_PandaCrazy"}).css({"font-size":"9px","margin-left":"10px"}).html("[PC] "));
  312. appendPandaButtons($(".JR_PandaCrazy:first"),requestersInfo);
  313. } else {
  314. var projectsControls = $(".row.projects-info-header, .row.task-queue-header");
  315. if (projectsControls.length) {
  316. var tempPrevDiv = $(projectsControls[0]).next().find(".col-xs-12:first");
  317. var reactInfo = tempPrevDiv.find("div:first").data("reactProps");
  318. reactInfo = reactInfo.bodyData;
  319. $(tempPrevDiv).find(".table-row").bind("DOMSubtreeModified", function() {
  320. if ($(this).find(".expanded-row").length) {
  321. if (!$(this).data("JR-expandedDesc")) {
  322. $(this).data({"JR-expandedDesc":"true"});
  323. var reactIDString = $(this).data("reactid");
  324. var reactID = reactIDString.split("$")[1];
  325. var thisJobData=parseHitsInfo(reactInfo[reactID]);
  326. $(this).find(".p-b-md,.task-info-column").append($("<div>").attr({"class":"JR_PandaCrazy"})
  327. .css({"font-size":"10px","margin-left":"10px"}).html("[PC] "));
  328. appendPandaButtons($(this).find(".JR_PandaCrazy:first"),thisJobData);
  329. }
  330. } else { $(this).removeData("JR-expandedDesc"); }
  331. });
  332. }
  333. }
  334. setTimeout( findProjectedEarnings,900 );
  335. }
  336. }
  337. }
  338. function fixJson(theNode) { // only used to fix hitscraper.
  339. $(theNode).find("a[href*='/projects/']").each( function() {
  340. $(this).attr("href",$(this).attr("href").replace(".json",""));
  341. });
  342. }
  343. function holdGIDLinks(theNode) {
  344. document.onclick = function(event) {
  345. if (event===undefined) event= window.event;
  346. var target= 'target' in event? event.target : event.srcElement, secondPart = "", jobData = null;
  347. if (target.tagName == "A" && target.href.indexOf("/projects/")) {
  348. if ($(target).closest("td.ctaBbcodeTableCellLeft").length) jobData = format1($(target),$(target).closest("td.ctaBbcodeTableCellLeft"));
  349. else if ($(target).closest("td.cms_table_td").length) jobData = format1($(target),$(target).closest("td.cms_table_td"));
  350. else if (gLocation.indexOf("mturkforum.com") != -1) jobData = format1($(target),$(target).closest("td"));
  351. else if ($(target).closest("blockquote.messageText").length) jobData = format2($(target),$(target).closest("blockquote.messageText"));
  352. else if ($(target).closest("a[href*='turkerview.com/requesters/']").length) jobData = format3($(target),$(target).closest("a[href*='turkerview.com/requesters/']"));
  353. else if ($(target).find("b:contains('TurkerView:')").length) jobData = format3($(target),$(target).find("b:contains('TurkerView:')"));
  354. else {
  355. secondPart = target.href.split("/projects/")[1]; var thisGID = (secondPart) ? secondPart.split("/")[0] : "";
  356. jobData = {"GID":thisGID,"RID":"","RName":"","Title":"","Reward":""};
  357. }
  358. if (jobData.GID!=="") {
  359. GM_setValue("JRHoldGID",jobData.GID);
  360. GM_setValue("JRHoldRID",jobData.RID);
  361. GM_setValue("JRHoldRName",unescape(jobData.RName));
  362. GM_setValue("JRHoldTitle",unescape(jobData.Title));
  363. GM_setValue("JRHoldReward",unescape(jobData.Reward));
  364. }
  365. }
  366. };
  367. }
  368. function setUpObserver(theNode,addButtons,jsonFix,hitnotifier) {
  369. var targetObserveNode = theNode;
  370. var config = { childList: true };
  371. var callback = function(mutations) {
  372. for (var index = 0,len=mutations.length; index < len; index++) {
  373. var thisMutationNode = mutations[index].addedNodes;
  374. for (var index2 = 0,len2=thisMutationNode.length; index2 < len2; index2++) {
  375. if (addButtons) addMessageButtons(thisMutationNode[index2]);
  376. if (jsonFix) fixJson(thisMutationNode[index2]);
  377. }
  378. }
  379. };
  380. var observer = new MutationObserver(callback);
  381. observer.observe(targetObserveNode, config);
  382. }
  383. if (locationForums()) {
  384. setTimeout( function() {
  385. holdGIDLinks($("body"));
  386. addPageButtons();
  387. if ($("#messageList").length) { // forums
  388. setUpObserver($("#messageList")[0],true,false,false);
  389. } else if ($(".block--messages .block-body").length) { // new Mturkcrowd.com
  390. setUpObserver($(".block--messages .block-body")[0],true,false,false);
  391. }
  392. }, 600);
  393. } else if (gLocation.indexOf("hitnotifier.com") != -1) {
  394. document.addEventListener("pandaCrazy", function(event) { //(event) => {
  395. var hit = event.detail.project;
  396. var pcCommand = (event.detail.once) ? "PandaCrazyOnce" : "PandaCrazyAdd";
  397. var thisRegex = />Reward *:<\D*(\d+\.\d\d)</;
  398. var rewardAmount = thisRegex.exec(event.detail.html)[1];
  399. window.open("https://worker.mturk.com/requesters/" + pcCommand + "/projects?JRGID=" + hit.hit_set_id + "&JRRName=" +hit.requester_name +
  400. "&JRRID=" + hit.requester_id + "&JRTitle=" + hit.title + "&JRReward=" + rewardAmount, "PandaCommand", "height=200,width=200");
  401. });
  402. } else {
  403. $(function() {
  404. if (gLocation.indexOf("worker.mturk.com") != -1) gNewSite = true;
  405. if (gLocation.indexOf("worker.mturk.com/requesters/PandaCrazy") != -1) {
  406. var sendFormat = (gLocation.indexOf("PandaCrazyAdd") != -1) ? 1 : (gLocation.indexOf("PandaCrazyOnce") != -1) ? 2 : (gLocation.indexOf("PandaCrazySearch") != -1) ? 3 : 0;
  407. if (sendFormat>0) {
  408. var jobData = jQuery.extend(true, {}, gJobDataDefault);
  409. if ( gLocation.indexOf("JRGID=") != -1) jobData.groupId = gLocation.split("JRGID=")[1].split("&")[0];
  410. if ( gLocation.indexOf("JRRID=") != -1) jobData.requesterId = gLocation.split("JRRID=")[1].split("&")[0];
  411. if ( gLocation.indexOf("JRRName=") != -1) jobData.requesterName = unescape(gLocation.split("JRRName=")[1].split("&")[0]);
  412. if ( gLocation.indexOf("JRTitle=") != -1) jobData.title = unescape(gLocation.split("JRTitle=")[1].split("&")[0]);
  413. if ( gLocation.indexOf("JRReward=") != -1) jobData.pay = unescape(gLocation.split("JRReward=")[1].split("&")[0]);
  414. if (sendFormat==1) sendJobData(jobData);
  415. else if (sendFormat==2) sendJobOnceData(jobData);
  416. else sendJobSearchData(jobData);
  417. setTimeout( function() { window.top.close(); },300);
  418. }
  419. } else if (gLocation.indexOf("mturk.com/") != -1) {
  420. holdGIDLinks($("body"));
  421. if ( !$(".navbar-sub-nav.navbar-nav:contains('Your HITs Queue')").length ) {
  422. $(".nav.navbar-nav.hidden-xs-down:not(:contains('HITs Queue'))").append('<li class="nav-item"><a class="nav-link" href="https://worker.mturk.com/tasks">HITs Queue</a></li>');
  423. }
  424. if ( gLocation.indexOf("/tasks") == -1 && $("button:contains('Return')").length ) {
  425. $(".col-xs-12.navbar-content a.navbar-brand:first").after("<div class='navbar-divider hidden-xs-down'></div><ul class='nav navbar-nav hidden-xs-down'><li class='nav-item'><a class='nav-link' style='color:white;' href='https://worker.mturk.com/tasks'>HITs Queue</a></li></ul>");
  426. }
  427. window.addEventListener("storage", mainListener, false);
  428. setTimeout( function() { sendPingMessage(); }, 500);
  429. }
  430. });
  431. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址