CH Plaintext HIT Export

Export HIT information in multi-line plain text format.

当前为 2015-01-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name CH Plaintext HIT Export
  3. // @description Export HIT information in multi-line plain text format.
  4. // @version 1.2c
  5. // @include https://www.mturk.com/mturk/findhits*
  6. // @include https://www.mturk.com/mturk/viewhits*
  7. // @include https://www.mturk.com/mturk/sorthits*
  8. // @include https://www.mturk.com/mturk/searchbar*selectedSearchType=hitgroups*
  9. // @include https://www.mturk.com/mturk/viewsearchbar*selectedSearchType=hitgroups*
  10. // @include https://www.mturk.com/mturk/sortsearchbar*HITGroup*
  11. // @include https://www.mturk.com/mturk/preview*
  12. // @grant GM_setClipboard
  13. // @author Cristo + clickhappier
  14. // @namespace mturkgrind
  15. // ==/UserScript==
  16.  
  17.  
  18. // based on 'IRC Export (reformatted output mod)': https://greasyfork.org/en/scripts/6254-irc-export-reformatted-output-mod
  19.  
  20.  
  21. var caps = document.getElementsByClassName('capsulelink');
  22. for (var c = 0; c < caps.length/2; c++){
  23. button = document.createElement('button');
  24. button.setAttribute("place",c);
  25. button.textContent = 'TXT';
  26. button.style.height = '14px';
  27. button.style.width = '30px';
  28. button.style.fontSize = '8px';
  29. button.style.border = '1px solid';
  30. button.style.padding = '0px';
  31. button.style.backgroundColor = 'transparent';
  32. button.title = 'Click to save Hit information to your clipboard';
  33. button.addEventListener("click", display, false);
  34. document.getElementById('capsule'+c+'-0').parentNode.appendChild(button);
  35. }
  36.  
  37. function getTO(f){
  38. var toComp = [];
  39. var toUrl = 'https://mturk-api.istrack.in/multi-attrs.php?ids='+f;
  40. requestTO = new XMLHttpRequest();
  41. requestTO.onreadystatechange = function () {
  42. if ((requestTO.readyState ===4) && (requestTO.status ===200)) {
  43. if(requestTO.responseText.split(':').length > 2){
  44. var toInfo = requestTO.responseText.split('{')[3].split('}')[0].split(',');
  45. for (var t = 0; t < 4; t++){
  46. var arrTo = toInfo[t].split(':');
  47. toComp.push(arrTo[1].substring(1,4));
  48. }
  49. } else {
  50. toComp = ['-','-','-','-'];
  51. }
  52. }
  53. }
  54. requestTO.open('GET', toUrl, false);
  55. requestTO.send(null);
  56. return toComp;
  57. }
  58.  
  59. function display(e){
  60. var theButton = e.target;
  61. theButton.style.backgroundColor = '#CC0000';
  62. setTimeout(function(){theButton.style.backgroundColor = 'transparent';},600);
  63. var capHand = document.getElementById('capsule'+theButton.getAttribute("place")+'-0');
  64. var tBodies = capHand.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  65. var capReq = tBodies.getElementsByClassName('requesterIdentity')[0].textContent;
  66. var capReqId = tBodies.getElementsByClassName('requesterIdentity')[0].parentNode.href.split('requesterId=')[1];
  67. var capTitle = capHand.textContent.trim();
  68. capTitle = capTitle.replace(/<(\w+)[^>]*>.*<\/\1>/gi, "").trim(); // addition to strip html tags and their contents, appearing inside the title link (re 10-20-2014 appearance of "<span class="tags"></span>")
  69.  
  70. var capGId = 'unavailable'; // handle logged-out export requests for HITs with no preview/notqualified links
  71. if ( capHand.parentNode.parentNode.getElementsByClassName('capsulelink')[1].firstChild.nextSibling.href != '' ) { // if hit has a preview/notqualified link
  72. capGId = capHand.parentNode.parentNode.getElementsByClassName('capsulelink')[1].firstChild.nextSibling.href.split('=')[1];
  73. capGId = capGId.replace("&hitId", ""); // Amazon messed up the notqualified links, now looking like https://www.mturk.com/mturk/notqualified?hitGroupId=3ID43DSF4IQ1X8LO308D15ZSD5J5GX&hitId=3ID43DSF4IQ1X8LO308D15ZSD5J5GX ; this and the above split happening on = instead of a specific value address that
  74. }
  75. var capRew = tBodies.getElementsByClassName('reward')[0].textContent;
  76.  
  77. var capTime = tBodies.getElementsByClassName('capsule_field_text')[2].textContent;
  78.  
  79. var capAvailable = tBodies.getElementsByClassName('capsule_field_text')[4].textContent;
  80.  
  81. var qualList = document.getElementById('capsule'+theButton.getAttribute("place")+'target').getElementsByTagName('tbody')[2];
  82. var qualColl = qualList.getElementsByTagName('td');
  83. var qualStart = 3;
  84. if ( document.getElementById('lnkWorkerSignin') ) { qualStart = 1; } // handle logged-out export requests - difference in qual table coding
  85. var masterStat = '';
  86. for ( var m = qualStart; m < qualColl.length; m++ ) {
  87. if ( qualColl[m].textContent.indexOf('Masters') > -1 ) {
  88. masterStat = 'MASTERS ';
  89. }
  90. }
  91. var capUrl = 'https://www.mturk.com/mturk/preview?groupId='+capGId;
  92. var capReqUrl = 'https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&requesterId='+capReqId;
  93. var hitLinkUnav = '';
  94. if ( capGId == 'unavailable' ) { capUrl = capReqUrl; hitLinkUnav = " (preview link unavailable)"; } // handle logged-out export requests for HITs with no preview/notqualified links
  95. var toLink = 'http://turkopticon.ucsd.edu/'+capReqId;
  96. var capToStats = getTO(capReqId);
  97.  
  98.  
  99. // additions for plaintext export:
  100. function DST() { // check if daylight savings time should be adjusted for, from http://www.mresoftware.com/simpleDST.htm
  101. var today = new Date();
  102. var yr = today.getFullYear();
  103. var dst_start = new Date("March 14, "+yr+" 02:00:00"); // 2nd Sunday in March can't occur after the 14th
  104. var dst_end = new Date("November 07, "+yr+" 02:00:00"); // 1st Sunday in November can't occur after the 7th
  105. var day = dst_start.getDay(); // day of week of 14th
  106. dst_start.setDate(14-day); // Calculate 2nd Sunday in March of this year
  107. day = dst_end.getDay(); // day of the week of 7th
  108. dst_end.setDate(7-day); // Calculate first Sunday in November of this year
  109. if (today >= dst_start && today < dst_end) { //does today fall inside of DST period?
  110. return true; //if so then return true
  111. }
  112. return false; //if not then return false
  113. }
  114.  
  115. var currentDate = new Date();
  116. var utc = currentDate.getTime() + (currentDate.getTimezoneOffset() * 60000); // http://www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/
  117. if ( DST() == true ) { var offset = "-7"; } else { var offset = "-8"; } // adjust Pacific Time's UTC offset for daylight savings time - http://stackoverflow.com/questions/8207655/how-to-get-time-of-specific-timezone-using-javascript/8207708#8207708
  118. var amazonDate = new Date(utc + (3600000*offset));
  119. var month = amazonDate.getMonth() + 1;
  120. var day = amazonDate.getDate();
  121. var year = amazonDate.getFullYear();
  122. var hours = amazonDate.getHours();
  123. if (hours < 10) { hours = '0' + hours; } // http://stackoverflow.com/questions/6838197/get-local-date-string-and-time-string/6838658#6838658
  124. var minutes = amazonDate.getMinutes();
  125. if (minutes < 10) { minutes = '0' + minutes; }
  126. var dateStr = month + "/" + day + "/" + year + " " + hours + ":" + minutes + " PT";
  127. var capDesc = '"' + tBodies.getElementsByClassName('capsule_field_text')[5].textContent.trim().replace(/(\t)+/g,' ').replace(/(\n)+/g,' ').replace(/(\r)+/g,' ').replace(/( )+/g,' ').replace(/(\s)+/g,' ') + '"';
  128. if (capDesc == '""') { capDesc = "none"; }
  129. var capKeywords = '"' + tBodies.getElementsByClassName('capsule_field_text')[6].textContent.trim().replace(/(\t)+/g,' ').replace(/(\n)+/g,' ').replace(/(\r)+/g,' ').replace(/( )+/g,' ').replace(/(\s)+/g,' ') + '"';
  130. if (capKeywords == '""') { capKeywords = "none"; }
  131.  
  132. var qualStr = "";
  133. for ( var q = qualStart; q < qualColl.length; q++ ) {
  134. if ( ( (qualColl[q].textContent.indexOf('is') > -1) || (qualColl[q].textContent.indexOf('has') > -1) ) && (qualColl[q].textContent.indexOf('You meet this') < 0) ) {
  135. if (qualStr != "") { qualStr += ' '; }
  136. qualStr += qualColl[q].textContent.trim().replace(/(\t)+/g,' ').replace(/(\n)+/g,' ').replace(/(\r)+/g,' ').replace(/( )+/g,' ').replace(/(\s)+/g,' ') + ' \r\n';
  137. }
  138. }
  139. if (qualStr == "") { qualStr = "none \r\n"; }
  140.  
  141.  
  142. var exString = dateStr + ' \r\n'
  143. + masterStat + 'HIT: ' + capTitle + ' - ' + capUrl + hitLinkUnav + ' \r\n'
  144. + 'Requester: ' + capReq + ' - ' + capReqUrl + ' \r\n'
  145. + 'TO Ratings: ' + 'Pay='+capToStats[1] + ' Fair='+capToStats[2] + ' Comm='+capToStats[0] + ' Speed='+capToStats[3] + ' - ' + toLink + ' \r\n'
  146. + 'Time Allotted: ' + capTime + ' \r\n'
  147. + 'Reward: ' + capRew + ' \r\n'
  148. + 'HITs Available: ' + capAvailable + ' \r\n'
  149. + 'Description: ' + capDesc + ' \r\n'
  150. + 'Keywords: ' + capKeywords + ' \r\n'
  151. + 'Qualifications: ' + qualStr + ' \r\n' ;
  152. GM_setClipboard(exString);
  153. }