[MTurk Worker] Return All HITs

Returns all HITs that are in your queue

  1. // ==UserScript==
  2. // @name [MTurk Worker] Return All HITs
  3. // @namespace https://github.com/Kadauchi
  4. // @version 1.0.1
  5. // @description Returns all HITs that are in your queue
  6. // @author Kadauchi
  7. // @icon http://i.imgur.com/oGRQwPN.png
  8. // @include https://worker.mturk.com/tasks*
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. const button = document.createElement(`button`);
  13. button.className = `m-l-sm text-black btn btn-default`;
  14. button.textContent = `Return All`;
  15. button.addEventListener(`click`, async (event) => {
  16. const c = confirm(`Are you sure you want to return all HITs?`);
  17.  
  18. if (c) {
  19. document.getElementsByClassName(`table-expand-collapse-button`)[0].click();
  20.  
  21. for (const form of document.forms) {
  22. try {
  23. const response = await fetch(form.action, {
  24. method: `post`,
  25. credentials: `include`,
  26. body: new FormData(form)
  27. });
  28. }
  29. catch (error) {
  30. console.log(`Expected error:`, error);
  31. }
  32.  
  33. form.closest(`.table-row`).style.display = `none`;
  34. }
  35. }
  36. });
  37.  
  38. document.getElementsByClassName(`expand-collapse-projects-holder`)[0].appendChild(button);
  39. })();