Greasy Fork is available in English.

[MTurk Worker] No HIT Reloader

Reloads pages automatically if no HIT is loaded for provided Group Ids

  1. // ==UserScript==
  2. // @name [MTurk Worker] No HIT Reloader
  3. // @namespace https://github.com/Kadauchi
  4. // @version 2.1.1
  5. // @description Reloads pages automatically if no HIT is loaded for provided Group Ids
  6. // @author Kadauchi
  7. // @icon http://i.imgur.com/oGRQwPN.png
  8. // @include https://worker.mturk.com/*
  9. // @grant GM_getTab
  10. // @grant GM_saveTab
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. GM_getTab((tab) => {
  15. const gid = location.href.match(/projects\/([A-Z0-9]+)/) ? location.href.match(/projects\/([A-Z0-9]+)/)[1] : null;
  16. const gids = localStorage.NHR_gids ? JSON.parse(localStorage.NHR_gids) : {};
  17.  
  18. let timeout = null;
  19.  
  20. const reloader = () => {
  21. if (!gid && gids[tab.gid]) {
  22. timeout = setTimeout(() => {
  23. window.location.replace(`https://worker.mturk.com/projects/${tab.gid}/tasks/accept_random`);
  24. }, 500);
  25. }
  26. else {
  27. clearTimeout(timeout);
  28. }
  29. };
  30.  
  31. if (location.href.indexOf(`https://worker.mturk.com/projects`) !== -1) {
  32. if (gid) {
  33. tab.gid = gid;
  34. }
  35. else {
  36. reloader();
  37. }
  38.  
  39. if (tab.gid) {
  40. const button = document.createElement(`button`);
  41. button.title = `Auto Reload ${tab.gid} If No HIT?`;
  42. button.className = `m-l-sm fa fa-refresh btn ${gids[tab.gid] ? `btn-success` : `btn-default`}`;
  43. button.addEventListener(`click`, (event) => {
  44. button.classList.toggle(`btn-success`);
  45. button.classList.toggle(`btn-default`);
  46.  
  47. gids[tab.gid] = button.classList.contains(`btn-success`);
  48. localStorage.NHR_gids = JSON.stringify(gids);
  49.  
  50. reloader();
  51. });
  52.  
  53. document.getElementsByClassName(`navbar-content`)[0].appendChild(button);
  54. }
  55. }
  56. else {
  57. tab.gid = undefined;
  58. }
  59.  
  60. GM_saveTab(tab);
  61. });
  62. })();