CH Plaintext HIT Export

Export HIT information in multi-line plain text format.

目前為 2015-02-13 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name CH Plaintext HIT Export
  3. // @description Export HIT information in multi-line plain text format.
  4. // @version 1.3c
  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. // output display box
  60. var txtexportdiv = document.createElement('div');
  61. var txtexporttextarea = document.createElement('textarea');
  62. txtexportdiv.style.position = 'fixed';
  63. txtexportdiv.style.width = '500px';
  64. txtexportdiv.style.height = '255px';
  65. txtexportdiv.style.left = '50%';
  66. txtexportdiv.style.right = '50%';
  67. txtexportdiv.style.margin = '-250px 0px 0px -250px';
  68. txtexportdiv.style.top = '300px';
  69. txtexportdiv.style.padding = '5px';
  70. txtexportdiv.style.border = '2px';
  71. txtexportdiv.style.backgroundColor = 'black';
  72. txtexportdiv.style.color = 'white';
  73. txtexportdiv.style.zIndex = '100';
  74. txtexportdiv.setAttribute('id','txtexport_div');
  75. txtexportdiv.style.display = 'none';
  76. txtexporttextarea.style.padding = '2px';
  77. txtexporttextarea.style.width = '500px';
  78. txtexporttextarea.style.height = '230px';
  79. txtexporttextarea.title = 'Plaintext Export Output';
  80. txtexporttextarea.setAttribute('id','txtexport_text');
  81. txtexportdiv.textContent = 'Plaintext Export: Press Ctrl+C to (re-)copy to clipboard. Click textarea to close.';
  82. txtexportdiv.style.fontSize = '12px';
  83. txtexportdiv.appendChild(txtexporttextarea);
  84. document.body.insertBefore(txtexportdiv, document.body.firstChild);
  85. txtexporttextarea.addEventListener("click", function(){ txtexportdiv.style.display = 'none'; }, false);
  86.  
  87.  
  88. function display(e){
  89. var theButton = e.target;
  90. theButton.style.backgroundColor = '#CC0000';
  91. var capHand = document.getElementById('capsule'+theButton.getAttribute("place")+'-0');
  92. var tBodies = capHand.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  93. var capReq = tBodies.getElementsByClassName('requesterIdentity')[0].textContent;
  94. var capReqId = tBodies.getElementsByClassName('requesterIdentity')[0].parentNode.href.split('requesterId=')[1];
  95. var capTitle = capHand.textContent.trim();
  96. 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>")
  97.  
  98. var capGId = 'unavailable'; // handle logged-out export requests for HITs with no preview/notqualified links
  99. if ( capHand.parentNode.parentNode.getElementsByClassName('capsulelink')[1].firstChild.nextSibling.href != '' ) { // if hit has a preview/notqualified link
  100. capGId = capHand.parentNode.parentNode.getElementsByClassName('capsulelink')[1].firstChild.nextSibling.href.split('=')[1];
  101. 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
  102. }
  103. var capRew = tBodies.getElementsByClassName('reward')[0].textContent;
  104.  
  105. var capTime = tBodies.getElementsByClassName('capsule_field_text')[2].textContent;
  106.  
  107. var capAvailable = tBodies.getElementsByClassName('capsule_field_text')[4].textContent;
  108.  
  109. var qualList = document.getElementById('capsule'+theButton.getAttribute("place")+'target').getElementsByTagName('tbody')[2];
  110. var qualColl = qualList.getElementsByTagName('td');
  111. var qualStart = 3;
  112. if ( document.getElementById('lnkWorkerSignin') ) { qualStart = 1; } // handle logged-out export requests - difference in qual table coding
  113. var masterStat = '';
  114. for ( var m = qualStart; m < qualColl.length; m++ ) {
  115. if ( qualColl[m].textContent.indexOf('Masters') > -1 ) {
  116. masterStat = 'MASTERS ';
  117. }
  118. }
  119. var capUrl = 'https://www.mturk.com/mturk/preview?groupId='+capGId;
  120. var capReqUrl = 'https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&requesterId='+capReqId;
  121. var hitLinkUnav = '';
  122. if ( capGId == 'unavailable' ) { capUrl = capReqUrl; hitLinkUnav = " (preview link unavailable)"; } // handle logged-out export requests for HITs with no preview/notqualified links
  123. var toLink = 'http://turkopticon.ucsd.edu/'+capReqId;
  124. var capToStats = getTO(capReqId);
  125.  
  126.  
  127. // additions for plaintext export:
  128. function DST() { // check if daylight savings time should be adjusted for, from http://www.mresoftware.com/simpleDST.htm
  129. var today = new Date();
  130. var yr = today.getFullYear();
  131. var dst_start = new Date("March 14, "+yr+" 02:00:00"); // 2nd Sunday in March can't occur after the 14th
  132. var dst_end = new Date("November 07, "+yr+" 02:00:00"); // 1st Sunday in November can't occur after the 7th
  133. var day = dst_start.getDay(); // day of week of 14th
  134. dst_start.setDate(14-day); // Calculate 2nd Sunday in March of this year
  135. day = dst_end.getDay(); // day of the week of 7th
  136. dst_end.setDate(7-day); // Calculate first Sunday in November of this year
  137. if (today >= dst_start && today < dst_end) { //does today fall inside of DST period?
  138. return true; //if so then return true
  139. }
  140. return false; //if not then return false
  141. }
  142.  
  143. var currentDate = new Date();
  144. var utc = currentDate.getTime() + (currentDate.getTimezoneOffset() * 60000); // http://www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/
  145. 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
  146. var amazonDate = new Date(utc + (3600000*offset));
  147. var month = amazonDate.getMonth() + 1;
  148. var day = amazonDate.getDate();
  149. var year = amazonDate.getFullYear();
  150. var hours = amazonDate.getHours();
  151. if (hours < 10) { hours = '0' + hours; } // http://stackoverflow.com/questions/6838197/get-local-date-string-and-time-string/6838658#6838658
  152. var minutes = amazonDate.getMinutes();
  153. if (minutes < 10) { minutes = '0' + minutes; }
  154. var dateStr = month + "/" + day + "/" + year + " " + hours + ":" + minutes + " PT";
  155. var capDesc = '"' + tBodies.getElementsByClassName('capsule_field_text')[5].textContent.trim().replace(/(\t)+/g,' ').replace(/(\n)+/g,' ').replace(/(\r)+/g,' ').replace(/( )+/g,' ').replace(/(\s)+/g,' ') + '"';
  156. if (capDesc == '""') { capDesc = "none"; }
  157. var capKeywords = '"' + tBodies.getElementsByClassName('capsule_field_text')[6].textContent.trim().replace(/(\t)+/g,' ').replace(/(\n)+/g,' ').replace(/(\r)+/g,' ').replace(/( )+/g,' ').replace(/(\s)+/g,' ') + '"';
  158. if (capKeywords == '""') { capKeywords = "none"; }
  159.  
  160. var qualStr = "";
  161. for ( var q = qualStart; q < qualColl.length; q++ ) {
  162. if ( ( (qualColl[q].textContent.indexOf('is') > -1) || (qualColl[q].textContent.indexOf('has') > -1) ) && (qualColl[q].textContent.indexOf('You meet this') < 0) ) {
  163. if (qualStr != "") { qualStr += ' '; }
  164. qualStr += qualColl[q].textContent.trim().replace(/(\t)+/g,' ').replace(/(\n)+/g,' ').replace(/(\r)+/g,' ').replace(/( )+/g,' ').replace(/(\s)+/g,' ') + ' \r\n';
  165. }
  166. }
  167. if (qualStr == "") { qualStr = "none \r\n"; }
  168.  
  169.  
  170. var exString = dateStr + ' \r\n'
  171. + masterStat + 'HIT: ' + capTitle + ' - ' + capUrl + hitLinkUnav + ' \r\n'
  172. + 'Requester: ' + capReq + ' - ' + capReqUrl + ' \r\n'
  173. + 'TO Ratings: ' + 'Pay='+capToStats[1] + ' Fair='+capToStats[2] + ' Comm='+capToStats[0] + ' Speed='+capToStats[3] + ' - ' + toLink + ' \r\n'
  174. + 'Time Allotted: ' + capTime + ' \r\n'
  175. + 'Reward: ' + capRew + ' \r\n'
  176. + 'HITs Available: ' + capAvailable + ' \r\n'
  177. + 'Description: ' + capDesc + ' \r\n'
  178. + 'Keywords: ' + capKeywords + ' \r\n'
  179. + 'Qualifications: ' + qualStr + ' \r\n' ;
  180. GM_setClipboard(exString);
  181. window.setTimeout(function(){ theButton.style.backgroundColor = 'transparent'; }, 500);
  182. txtexporttextarea.textContent = exString;
  183. txtexportdiv.style.display = 'block';
  184. txtexporttextarea.select();
  185. }