mmmturkeybacon Save Automatic Approval Time

Saves automatic approval time and shows the time

  1. // ==UserScript==
  2. // @name mmmturkeybacon Save Automatic Approval Time
  3. // @author mmmturkeybacon
  4. // @description Saves automatic approval time and shows the time
  5. // remaining until approval in the status field of
  6. // completed HITs that are still pending approval.
  7. // Displays the total automatic approval time when
  8. // the mouse pointer hovers over the status field.
  9. // @namespace http://userscripts.org/users/523367
  10. // @match https://www.mturk.com/mturk/accept*
  11. // @match https://www.mturk.com/mturk/preview*
  12. // @match https://www.mturk.com/mturk/continue*
  13. // @match https://www.mturk.com/mturk/submit
  14. // @match https://www.mturk.com/mturk/return*
  15. // @match https://www.mturk.com/mturk/statusdetail*
  16. // @require http://code.jquery.com/jquery-latest.min.js
  17. // @version 1.54
  18. // @grant none
  19. // ==/UserScript==
  20.  
  21. /*
  22. * Automatic approval data is saved whenever a HIT page is unloaded. Usually when a
  23. * HIT page is unloaded it means the HIT was submitted, but this isn't necessarily
  24. * so. It could also be that the user accepted the HIT, then closed the tab to
  25. * work on the HIT from his queue later. If this is the case, once the user eventually
  26. * submits the HIT the automatic approval data will be updated when the page unloads.
  27. * However, if the user returns the HIT then automatic approval data will have been
  28. * saved in local storage that isn't associated with any completed HITs. There's really
  29. * no good way to prevent this from happening or to remove the data.
  30. */
  31.  
  32. var hit_returned = false;
  33.  
  34. function create_title_str(hitId)
  35. {
  36. var title_str = '';
  37. var autoapprove_data = localStorage.getItem('autoapprove_data.' + hitId);
  38. if (autoapprove_data == null)
  39. {
  40. return title_str;
  41. }
  42. var hitAutoAppDelayInSeconds = parseInt(autoapprove_data.split('?')[1]);
  43.  
  44. if (hitAutoAppDelayInSeconds)
  45. {
  46. // time formatting code modified from http://userscripts.org/scripts/show/169154
  47. var days = Math.floor((hitAutoAppDelayInSeconds/(60*60*24)));
  48. var hours = Math.floor((hitAutoAppDelayInSeconds/(60*60)) % 24);
  49. var mins = Math.floor((hitAutoAppDelayInSeconds/60) % 60);
  50. var secs = hitAutoAppDelayInSeconds % 60;
  51. title_str = 'Automatically approved after ';
  52. title_str += (days == 0 ? '' : days + (days > 1 ? ' days ' : ' day ')) +
  53. (hours == 0 ? '' : hours + (hours > 1 ? ' hours ' : ' hour ')) +
  54. (mins == 0 ? '' : mins + (mins > 1 ? ' minutes ' : ' minute ')) +
  55. (secs == 0 ? '' : secs + (secs > 1 ? ' seconds' : ' second'));
  56. }
  57. else if (hitAutoAppDelayInSeconds == 0)
  58. {
  59. title_str = "Automatically approved after 0 seconds";
  60. }
  61. return title_str;
  62. }
  63.  
  64. function create_time_remaining_str(hitId)
  65. {
  66. var time_str = '';
  67. var autoapprove_data = localStorage.getItem('autoapprove_data.' + hitId);
  68. if (autoapprove_data == null)
  69. {
  70. return time_str;
  71. }
  72. var submit_time_seconds = parseInt(autoapprove_data.split('?')[0]);
  73. var hitAutoAppDelayInSeconds = parseInt(autoapprove_data.split('?')[1]);
  74. var now_in_seconds = new Date().getTime()/1000;
  75. var seconds_remaining = Math.round(submit_time_seconds + hitAutoAppDelayInSeconds - now_in_seconds);
  76.  
  77. if (seconds_remaining > 0)
  78. {
  79. // time formatting code modified from http://userscripts.org/scripts/show/169154
  80. var days = Math.floor((seconds_remaining/(60*60*24)));
  81. var hours = Math.floor((seconds_remaining/(60*60)) % 24);
  82. var mins = Math.floor((seconds_remaining/60) % 60);
  83. var secs = seconds_remaining % 60;
  84. time_str = '\n(';
  85. time_str += (days == 0 ? '' : days + 'd') +
  86. (hours == 0 ? '' : hours + 'h') +
  87. (mins == 0 ? '' : mins + 'm') +
  88. (secs == 0 ? '' : secs + 's');
  89. time_str += ')';
  90. if (seconds_remaining == 0)
  91. {
  92. time_str = "\n(0 seconds)";
  93. }
  94. }
  95. return time_str;
  96. }
  97.  
  98. function store_autoapprove_data()
  99. {
  100. var $isAccepted = $('input[type="hidden"][name="isAccepted"][value="true"]')
  101. if ($isAccepted.length > 0 && !hit_returned)
  102. {
  103. var hitReview_hitId = $('form[name="hitForm"][action="/mturk/hitReview"] input[name="hitId"]').val();
  104. var hitAutoAppDelayInSeconds = $('input[type="hidden"][name="hitAutoAppDelayInSeconds"]').val();
  105. var now_in_seconds = new Date().getTime()/1000;
  106. var autoapprove_data = now_in_seconds +'?'+ hitAutoAppDelayInSeconds;
  107. localStorage.setItem('autoapprove_data.' + hitReview_hitId, autoapprove_data);
  108. }
  109. }
  110.  
  111. if(typeof(Storage)!=="undefined")
  112. {
  113. // modified return click snippet from https://userscripts.org/scripts/review/175838
  114. $('img[src="/images/return_hit.gif"]').parent().click(function()
  115. {
  116. hit_returned = true;
  117. });
  118.  
  119. window.addEventListener('beforeunload', store_autoapprove_data);
  120.  
  121. var $requesters = $('td[class="statusdetailRequesterColumnValue"]');
  122. if ($requesters.length > 0)
  123. {
  124. $requesters.each(function()
  125. {
  126. // trick to get hitId snippet from http://userscripts.org/scripts/show/170845
  127. var hitId = $(this).find('a[href^="/mturk/contact?"]').attr('href').match(/[A-Z0-9]{30}/);
  128. var $status_value = $(this).parent().find('td[class="statusdetailStatusColumnValue"]');
  129.  
  130. var title_str = create_title_str(hitId);
  131. $status_value.attr('title', title_str);
  132.  
  133. if ($status_value.text() == 'Pending Approval')
  134. {
  135. var time_remaining_str = create_time_remaining_str(hitId);
  136. var status_value = $status_value.text() + time_remaining_str;
  137. $status_value.text(status_value);
  138. }
  139. });
  140. }
  141. }