Simple Queue Low Time Alert

Alert if time is running out on HITs

  1. // ==UserScript==
  2. // @name Simple Queue Low Time Alert
  3. // @version 1.1
  4. // @description Alert if time is running out on HITs
  5. // @author slothbear
  6. // @icon http://i.imgur.com/yptTSAh.gif
  7. // @include https://worker.mturk.com/tasks*
  8.  
  9. // @namespace https://greasyfork.org/users/64880
  10. // ==/UserScript==
  11.  
  12.  
  13. // This script watches the shortest timer in the queue
  14. // and plays an audio alert if it falls under a certain
  15. // number of minutes (default is 10).
  16. //
  17. // The script will reload the queue every 15 seconds while
  18. // a timer is going off so it can reset and not be annoying.
  19.  
  20.  
  21.  
  22.  
  23. //alert time in minutes
  24. //set to 100 to test or debug
  25. const WARNING_TIMER = 10;
  26.  
  27.  
  28.  
  29. function watchTimer(timer, audioElement) {
  30. var warningClock = 0;
  31. let originalTitle = document.title;
  32.  
  33. setInterval(function(){
  34. let time = extractMinutesFromTime(timer.innerText);
  35. let visualTrigger = false;
  36. if (checkMinutesLeft(time)) {
  37. if (warningClock === 0) audioAlert(audioElement);
  38. if (warningClock === 14) window.location.reload();
  39. warningClock++;
  40. visualTrigger = true;
  41. } else {
  42. visualTrigger = false;
  43. }
  44. if (visualTrigger) visualAlert(warningClock, originalTitle);
  45. }, 1000);
  46. }
  47.  
  48. function extractMinutesFromTime(time) {
  49. let length = time.length;
  50. let minutes;
  51. if (length > 5) minutes = 99; // this happens if over 1 hour left
  52. if (length === 5) minutes = time.substring(length-5,length-3);
  53. if (length < 5) minutes = time.substring(length-4,length-3);
  54. return minutes;
  55. }
  56.  
  57. function visualAlert(count, originalTitle) {
  58. let firstRow = document.querySelector('li.table-row');
  59. if (count %2 === 0) {
  60. document.title = "█████████████████████";
  61. firstRow.style.backgroundColor = "#D66462";
  62. } else {
  63. document.title = originalTitle;
  64. firstRow.style.backgroundColor = "#DCC784";
  65. }
  66. }
  67.  
  68. function init_audio() {
  69. let audioElement = [];
  70. audioElement[0] = document.createElement('audio');
  71. audioElement[0].setAttribute('src', 'http://themushroomkingdom.net/sounds/wav/smb/smb_warning.wav');
  72. return audioElement;
  73. }
  74.  
  75. function audioAlert(audioElement) {
  76. console.log("Tasks are about to expire. HURRY!");
  77. audioElement[0].play();
  78. }
  79.  
  80. function grabFocus() {
  81. let quickFocus = window.open("https://www.chronicle.com/blogs/linguafranca/files/2017/11/Nothing-to-See-15a34a2fc727c8.jpg", "_blank");
  82. quickFocus.close();
  83. }
  84.  
  85. function getTimer(pos) {
  86. return document.querySelectorAll('span.completion-timer')[pos];
  87. }
  88.  
  89. function minutesToSeconds(minutes) {
  90. return minutes * 60;
  91. }
  92.  
  93. function checkMinutesLeft(time) {
  94. return (time < WARNING_TIMER);
  95. }
  96.  
  97.  
  98.  
  99. (function main() {
  100.  
  101. //checks for a completion timer,
  102. //then stops if none found.
  103. let shortestTimer = getTimer(0);
  104. if (!shortestTimer) return false;
  105.  
  106. //get the audio setup so the file is ready
  107. //and then start watching the shortest timer
  108. let audioElement = init_audio();
  109. watchTimer(shortestTimer, audioElement);
  110.  
  111. })();