Greasy Fork 支持简体中文。

mTurk Parent Window Command Accepter

Updated for the Worker-only (no WWW) world.

  1. // ==UserScript==
  2. // @name mTurk Parent Window Command Accepter
  3. // @namespace salembeats
  4. // @version 2.6
  5. // @description Updated for the Worker-only (no WWW) world.
  6. // @include https://www.mturk.com/mturk/preview?*
  7. // @include https://www.mturk.com/mturk/accept?*
  8. // @include https://www.mturk.com/mturk/continue?*
  9. // @include https://www.mturk.com/mturk/return?*
  10. // @include https://worker.mturk.com/projects/*/tasks*
  11. // @icon http://ez-link.us/sb-png
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. // Targeting just active HITs would be @include https://worker.mturk.com/projects/*/tasks/*?assignment_id=*
  16.  
  17. (function() {
  18.  
  19. let childIFrame = document.querySelector("iframe");
  20. let childWindow = childIFrame.contentWindow;
  21.  
  22. let acceptHITButton = document.querySelector("span[data-react-class*='SubmitAcceptTaskFormButton'] button");
  23.  
  24. let secondaryButton = document.querySelector("input[name='authenticity_token']~button.btn.btn-secondary");
  25. let returnHITButton;
  26. if(secondaryButton.innerText.trim() === "Return") {returnHITButton = secondaryButton;}
  27.  
  28. let reactDetails = JSON.parse(document.querySelector(`div[data-react-class="require('reactComponents/common/ShowModal')['default']"]`).dataset.reactProps).modalOptions;
  29.  
  30. window.addEventListener('message', function(event) {
  31. let receivedObject = event.data;
  32.  
  33. if(receivedObject.hasOwnProperty("mTurkParentWindowQuery")) {
  34.  
  35. let objectToReplyWith = {};
  36.  
  37. if(receivedObject["mTurkParentWindowQuery"] === "accepted") {
  38.  
  39. let responseString = "";
  40.  
  41. if(returnHITButton) {responseString = "accepted";} else {responseString = "notAccepted";}
  42.  
  43. objectToReplyWith["mTurkParentWindowResponse"] = responseString;
  44. }
  45.  
  46. if(receivedObject["mTurkParentWindowQuery"] === "url") {
  47.  
  48. objectToReplyWith["urlResponse"] = window.location.href;
  49. }
  50.  
  51. if(receivedObject["mTurkParentWindowQuery"] === "hitDetails") {
  52.  
  53. objectToReplyWith["hitDetails"] = JSON.stringify(reactDetails);
  54. }
  55.  
  56. childWindow.postMessage(objectToReplyWith, "*");
  57. }
  58.  
  59. if(receivedObject.hasOwnProperty("mTurkParentWindowAction")) {
  60.  
  61. if(receivedObject["mTurkParentWindowAction"] === "accept" && acceptHITButton) {
  62. acceptHITButton.click();
  63. }
  64.  
  65. if(receivedObject["mTurkParentWindowAction"] === "return" && returnHITButton) {
  66. returnHITButton.click();
  67. }
  68.  
  69. if(receivedObject.mTurkParentWindowAction === "navigate") {
  70. window.location.href = receivedObject.url;
  71. }
  72. }
  73. });
  74. })();