mmmturkeybacon Floating Timers

Adds total time elapsed, time remaining, and task time elapsed to a floating display. The task timer keeps track of page load times to more accurately reflect the amount of required to finish a HIT.

  1. // ==UserScript==
  2. // @name mmmturkeybacon Floating Timers
  3. // @version 1.11
  4. // @description Adds total time elapsed, time remaining, and task time elapsed to a floating display. The task timer keeps track of page load times to more accurately reflect the amount of required to finish a HIT.
  5. // @author mmmturkeybacon
  6. // @namespace http://userscripts.org/users/523367
  7. // @match https://*.mturk.com/mturk/preview*
  8. // @match https://*.mturk.com/mturk/accept*
  9. // @match https://*.mturk.com/mturk/continue*
  10. // @match https://*.mturk.com/mturk/submit*
  11. // @match https://*.mturk.com/mturk/return*
  12. // @match https://www.mturk.com/mturk/takequalificationtest
  13. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  14. // @grant unsafeWindow
  15. // ==/UserScript==
  16.  
  17. // Given:
  18. // serverTimestamp (i.e. date of now)
  19. // totalSeconds (i.e. time alloted)
  20. // endTime (i.e. expiration time)
  21. // theTime (i.e. time elapsed)
  22. // Calculate:
  23. // start_time = endTime - totalSeconds
  24. // seconds_remaining = totalSeconds - theTime;
  25.  
  26. /* Set task_start_time as soon as possible, because page load time affects how long it takes to complete
  27. * a task. */
  28. var task_start_time = localStorage.getItem('mtb_page_unload_time');
  29. if (task_start_time == null)
  30. {
  31. task_start_time = (new Date()).getTime();
  32. }
  33.  
  34.  
  35. $(document).ready(function()
  36. //$(window).load(function()
  37. {
  38.  
  39. var isAccepted = document.evaluate("//input[@type='hidden' and @name='isAccepted' and @value='true']", document, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
  40.  
  41. if (isAccepted == true || document.location.href.indexOf('takequalificationtest') > -1)
  42. {
  43. var totalSeconds = unsafeWindow.totalSeconds;
  44.  
  45. var timer_holder = document.createElement("DIV");
  46. timer_holder.style.cssText = "position: fixed; top: 0px; left: 0px; z-index: 20; background-color: black;";
  47. timer_holder.align = "right";
  48.  
  49. var timer_holder_innerHTML = '<div><span id="elapsed_timer" title="Time elapsed since HIT accepted." style="font-size: 14px; color: white; font-family: verdana,arial,sans-serif; text-align: right;"></span></div>';
  50. timer_holder_innerHTML += '<div><span id="remaining_timer" title="Time remaining." style="font-size: 14px; color: white; font-family: verdana,arial,sans-serif; text-align: right;"></span></div>';
  51. timer_holder_innerHTML += '<div><span id="task_timer" title="Time elapsed since last HIT completed. Click to reset." style="font-size: 14px; color: white; font-family: verdana,arial,sans-serif; text-align: right;"></span></div>';
  52. timer_holder.innerHTML = timer_holder_innerHTML;
  53. document.body.insertBefore(timer_holder, document.body.firstChild);
  54. var theTime = document.getElementById("theTime");
  55. var elapsed_timer = document.getElementById("elapsed_timer");
  56. var remaining_timer = document.getElementById("remaining_timer");
  57. var task_timer = document.getElementById("task_timer");
  58. //var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  59. var observer = new MutationObserver(function(mutations)
  60. {
  61. elapsed_timer.innerHTML = theTime.innerHTML;
  62. var task_seconds_elapsed = Math.floor(((new Date()).getTime() - task_start_time)/1000);
  63. task_timer.innerHTML = format_time(task_seconds_elapsed);
  64. if (totalSeconds)
  65. {
  66. var seconds_remaining = totalSeconds - parse_theTime(theTime.innerHTML);
  67. remaining_timer.innerHTML = format_time(seconds_remaining);
  68. }
  69. else
  70. {
  71. remaining_timer.innerHTML = "error";
  72. }
  73. });
  74. var options = {
  75. attributes: false,
  76. characterData: true,
  77. childList: true,
  78. subtree: true
  79. };
  80. observer.observe(theTime, options);
  81.  
  82. task_timer.onclick = function(){task_start_time = (new Date()).getTime(); if(typeof(Storage)!=="undefined"){localStorage.setItem('mtb_page_unload_time', task_start_time);}};
  83. window.addEventListener('beforeunload', function(){if(typeof(Storage)!=="undefined"){localStorage.setItem('mtb_page_unload_time', (new Date()).getTime());}});
  84. }
  85.  
  86. });
  87.  
  88. function parse_theTime(theTime)
  89. {
  90. var dd = 0;
  91. var hh = 0;
  92. var mm = 0;
  93. var ss = 0;
  94. var seconds = 0;
  95.  
  96. var time_split = theTime.split(/:| /);
  97.  
  98. if (time_split.length == 4)
  99. {
  100. hh = parseInt(time_split[1], 10);
  101. mm = parseInt(time_split[2], 10);
  102. ss = parseInt(time_split[3], 10);
  103. }
  104. else if (time_split.length == 6)
  105. {
  106. dd = parseInt(time_split[1], 10);
  107. hh = parseInt(time_split[3], 10);
  108. mm = parseInt(time_split[4], 10);
  109. ss = parseInt(time_split[5], 10);
  110. }
  111.  
  112. seconds = (dd*24*60*60) + (hh*60*60) + (mm*60) + ss;
  113. return seconds;
  114. }
  115.  
  116.  
  117. function format_time(time_in_seconds)
  118. {
  119. var time_str = "error";
  120.  
  121. if (time_in_seconds >= 0)
  122. {
  123. // time formatting code modified from http://userscripts.org/scripts/show/169154
  124. var days = Math.floor((time_in_seconds/(60*60*24)));
  125. var hours = Math.floor((time_in_seconds/(60*60)) % 24);
  126. var minutes = Math.floor((time_in_seconds/60) % 60);
  127. var seconds = time_in_seconds % 60;
  128.  
  129. time_str = (days == 0 ? '' : days + (days > 1 ? ' days ' : ' day '));
  130.  
  131. if (hours < 10) {hours = "0"+hours;}
  132. if (minutes < 10) {minutes = "0"+minutes;}
  133. if (seconds < 10) {seconds = "0"+seconds;}
  134.  
  135. time_str += hours + ':' +minutes + ':' + seconds;
  136. }
  137.  
  138. return time_str;
  139. }

QingJ © 2025

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