TinyChat Export

Export HIT information in multi-line plain text format.

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
  1. // ==UserScript==
  2. // @name TinyChat Export
  3. // @description Export HIT information in multi-line plain text format.
  4. // @version 1.3c
  5. // @include https://www.mturk.com/mturk/searchbar*
  6. // @include https://www.mturk.com/mturk/findhits*
  7. // @include https://www.mturk.com/mturk/viewhits*
  8. // @include https://www.mturk.com/mturk/viewsearchbar*
  9. // @include https://www.mturk.com/mturk/sortsearchbar*
  10. // @include https://www.mturk.com/mturk/sorthits*
  11. // @grant GM_setClipboard
  12. // @author Cristo + clickhappier + jawz
  13. // @namespace https://greatest.deepsurf.us/users/1997
  14. // ==/UserScript==
  15.  
  16.  
  17. // based on 'IRC Export (reformatted output mod)': https://greatest.deepsurf.us/en/scripts/6254-irc-export-reformatted-output-mod
  18.  
  19.  
  20. var caps = document.getElementsByClassName('capsulelink');
  21. for (var c = 0; c < caps.length/2; c++){
  22. button = document.createElement('button');
  23. button.setAttribute("place",c);
  24. button.textContent = 'TXT';
  25. button.style.height = '14px';
  26. button.style.width = '30px';
  27. button.style.fontSize = '8px';
  28. button.style.border = '1px solid';
  29. button.style.padding = '0px';
  30. button.style.backgroundColor = 'transparent';
  31. button.title = 'Click to save Hit information to your clipboard';
  32. button.addEventListener("click", display, false);
  33. document.getElementById('capsule'+c+'-0').parentNode.appendChild(button);
  34. }
  35.  
  36. function getTO(f){
  37. var toComp = [];
  38. var toUrl = 'https://mturk-api.istrack.in/multi-attrs.php?ids='+f;
  39. requestTO = new XMLHttpRequest();
  40. requestTO.onreadystatechange = function () {
  41. if ((requestTO.readyState ===4) && (requestTO.status ===200)) {
  42. if(requestTO.responseText.split(':').length > 2){
  43. var toInfo = requestTO.responseText.split('{')[3].split('}')[0].split(',');
  44. for (var t = 0; t < 4; t++){
  45. var arrTo = toInfo[t].split(':');
  46. toComp.push(arrTo[1].substring(1,4));
  47. }
  48. } else {
  49. toComp = ['-','-','-','-'];
  50. }
  51. }
  52. }
  53. requestTO.open('GET', toUrl, false);
  54. requestTO.send(null);
  55. return toComp;
  56. }
  57.  
  58. function display(e){
  59. var theButton = e.target;
  60. theButton.style.backgroundColor = '#FD2B2B';
  61. setTimeout(function(){theButton.style.backgroundColor = 'transparent';},600);
  62. var capHand = document.getElementById('capsule'+theButton.getAttribute("place")+'-0');
  63. var tBodies = capHand.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  64. var capReq = tBodies.getElementsByClassName('requesterIdentity')[0].textContent;
  65. var capReqId = tBodies.getElementsByClassName('requesterIdentity')[0].parentNode.href.split('requesterId=')[1];
  66. var capTitle = capHand.textContent.trim();
  67. 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>")
  68. if (capHand.parentNode.parentNode.getElementsByClassName('capsulelink')[1].firstChild.href)
  69. var capGId = capHand.parentNode.parentNode.getElementsByClassName('capsulelink')[1].firstChild.href.split('groupId=')[1];
  70. else
  71. var capGId = capHand.parentNode.parentNode.getElementsByClassName('capsulelink')[1].firstChild.nextSibling.href.split('groupId=')[1];
  72. console.log(capGId)
  73. var capRew = tBodies.getElementsByClassName('reward')[0].textContent;
  74.  
  75. var capTime = tBodies.getElementsByClassName('capsule_field_text')[2].textContent;
  76.  
  77. var capAvailable = tBodies.getElementsByClassName('capsule_field_text')[4].textContent;
  78.  
  79. var qualList = document.getElementById('capsule'+theButton.getAttribute("place")+'target').getElementsByTagName('tbody')[2];
  80. var qualColl = qualList.getElementsByTagName('td');
  81. var masterStat = '';
  82. for ( var m = 3; m < qualColl.length; m++ ) {
  83. if ( qualColl[m].textContent.indexOf('Masters') > -1 ) {
  84. masterStat = 'MASTERS ';
  85. }
  86. }
  87. var capUrl = 'https://www.mturk.com/mturk/preview?groupId='+capGId;
  88. var capReqUrl = 'https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&requesterId='+capReqId;
  89. var toLink = 'http://turkopticon.ucsd.edu/'+capReqId;
  90. var capToStats = getTO(capReqId);
  91.  
  92.  
  93. // additions for plaintext export:
  94. function DST() { // check if daylight savings time should be adjusted for, from http://www.mresoftware.com/simpleDST.htm
  95. var today = new Date();
  96. var yr = today.getFullYear();
  97. var dst_start = new Date("March 14, "+yr+" 02:00:00"); // 2nd Sunday in March can't occur after the 14th
  98. var dst_end = new Date("November 07, "+yr+" 02:00:00"); // 1st Sunday in November can't occur after the 7th
  99. var day = dst_start.getDay(); // day of week of 14th
  100. dst_start.setDate(14-day); // Calculate 2nd Sunday in March of this year
  101. day = dst_end.getDay(); // day of the week of 7th
  102. dst_end.setDate(7-day); // Calculate first Sunday in November of this year
  103. if (today >= dst_start && today < dst_end) { //does today fall inside of DST period?
  104. return true; //if so then return true
  105. }
  106. return false; //if not then return false
  107. }
  108.  
  109. var currentDate = new Date();
  110. var utc = currentDate.getTime() + (currentDate.getTimezoneOffset() * 60000); // http://www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/
  111. 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
  112. var amazonDate = new Date(utc + (3600000*offset));
  113. var month = amazonDate.getMonth() + 1;
  114. var day = amazonDate.getDate();
  115. var year = amazonDate.getFullYear();
  116. var hours = amazonDate.getHours();
  117. if (hours < 10) { hours = '0' + hours; } // http://stackoverflow.com/questions/6838197/get-local-date-string-and-time-string/6838658#6838658
  118. var minutes = amazonDate.getMinutes();
  119. if (minutes < 10) { minutes = '0' + minutes; }
  120. var dateStr = month + "/" + day + "/" + year + " " + hours + ":" + minutes + " PT";
  121. var capDesc = '"' + tBodies.getElementsByClassName('capsule_field_text')[5].textContent.trim().replace(/(\t)+/g,' ').replace(/(\n)+/g,' ').replace(/(\r)+/g,' ').replace(/( )+/g,' ').replace(/(\s)+/g,' ') + '"';
  122. if (capDesc == '""') { capDesc = "none"; }
  123. var capKeywords = '"' + tBodies.getElementsByClassName('capsule_field_text')[6].textContent.trim().replace(/(\t)+/g,' ').replace(/(\n)+/g,' ').replace(/(\r)+/g,' ').replace(/( )+/g,' ').replace(/(\s)+/g,' ') + '"';
  124. if (capKeywords == '""') { capKeywords = "none"; }
  125.  
  126. var qualStr = "";
  127. for ( var q = 3; q < qualColl.length; q++ ) {
  128. if ( ( (qualColl[q].textContent.indexOf('is') > -1) || (qualColl[q].textContent.indexOf('has') > -1) ) && (qualColl[q].textContent.indexOf('You meet this') < 0) ) {
  129. if (qualStr != "") { qualStr += ' '; }
  130. qualStr += qualColl[q].textContent.trim().replace(/(\t)+/g,' ').replace(/(\n)+/g,' ').replace(/(\r)+/g,' ').replace(/( )+/g,' ').replace(/(\s)+/g,' ') + ' \r\n';
  131. }
  132. }
  133. if (qualStr == "") { qualStr = "none \r\n"; }
  134.  
  135.  
  136. var exString = masterStat + ' ' + capRew + ' - ' + ' ' + capTitle + ' - ' + ' ' + capUrl + ' - ' + capTime + ' - ' + ' ' + ' Requester: ' + capReq + ' - ' + ' TO: ' +capToStats[1] + ' - ' + ' ' + ' HITs Available: ' + capAvailable
  137. GM_setClipboard(exString);
  138. }