mmmturkeybacon Queue Order Fix

After completing a HIT anywhere within your queue (i.e. HITs Assigned To You), this script will automatically continue the HIT at the top of your queue.

当前为 2015-04-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name mmmturkeybacon Queue Order Fix
  3. // @version 2.14
  4. // @description After completing a HIT anywhere within your queue (i.e. HITs Assigned To You), this script will automatically continue the HIT at the top of your queue.
  5. // For example, if you sort your queue by Time Left (least first), you can use this script to work on the HITs that are closest to expiring instead of mturk's default behavior ignoring what your queue is sorted by and putting the oldest HIT next in line. You should only need to set the sort order once. HITs accepted after setting the sort order will be sorted automatically by mturk. Additionally you can manually continue the HIT at the top of your queue if you visit "https://www.mturk.com/mturk/myhits?first". Create a bookmark on your toolbar to quickly jump to the first HIT in your queue. This is especially useful if you just caught a HIT that will expire quickly.
  6. // @author mmmturkeybacon
  7. // @namespace http://userscripts.org/users/523367
  8. // @match https://*.mturk.com/mturk/myhits
  9. // @match https://*.mturk.com/mturk/myhits?first
  10. // @match https://*.mturk.com/mturk/sortmyhits?*
  11. // @match https://*.mturk.com/mturk/viewmyhits?*
  12. // @match https://*.mturk.com/mturk/continue*
  13. // @match https://*.mturk.com/mturk/submit
  14. // @match https://*.mturk.com/mturk/return?requesterId=*
  15. // @exclude https://*.mturk.com/mturk/continue*&MTBQOF+enabled=false
  16. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  17. // @grant GM_log
  18. // ==/UserScript==
  19.  
  20. /*
  21. * Mechanical Turk has two types of HITs. By far the ExternalQuestion HITs are
  22. * the most common. These HITs use an iframe to display the task, disable the
  23. * yellow Submit HIT button, and use the hidden link with the id hitExternalNextLink
  24. * to direct the browser to a new page after the task has been submitted in the
  25. * iframe. The second type of HIT is the QuestionForm HIT. These HITs do not use
  26. * an iframe, use the yellow Submit HIT button to submit, and do not use
  27. * hitExternalNextLink to direct the browser to a new page.
  28. *
  29. * For ExternalQuestion HITs, fixing the queue order is as simple as replacing
  30. * hitExternalNextLink with the URL of the next link you wish to work on.
  31. *
  32. * QuestionForm HITs don't use the hitExternalNextLink, however we can utilize
  33. * the fact that after a QuestionForm HIT is submitted the URL ends with
  34. * /mturk/submit to redirect the browser to the top of the queue.
  35. *
  36. */
  37.  
  38. /* NOTE: This script doesn't actually do anything on the /mturk/myhits page but running it on that page makes it convenient to disable the script by unchecking it in the greasemonkey dropdown menu. */
  39.  
  40. /* A previous version of this script bound to the return key, but using "@grant none" was required to coexist with MTurk Confirm Return HIT. I think it is better to run in the sandbox
  41. * and not worrry about jquery conflicts so now this script simply redirects to the head of the queue when it sees the /mturk/return? URL. */
  42. //j$ = this.$ = this.jQuery = jQuery.noConflict(true);
  43.  
  44. var TIMEOUT_TIMELIMIT = 10000; // 10000 [ms]
  45. var ON_ERROR_REDIRECT_URL = '/mturk/myhits';
  46. var DEFAULT_SORT_URL = '/mturk/sortmyhits?searchSpec=HITSearch%23T%231%2326%23-1%23T%23!Status!0!rO0ABXQACEFzc2lnbmVk!%23!Deadline!0!%23!&selectedSearchType=hitgroups&searchWords=&sortType=Deadline%3A0'; // a maximum of 26 HITs on a single page
  47.  
  48. $(document).ready(function()
  49. {
  50. var this_URL = window.location.href.split("mturk.com")[1];
  51. /* preview?groupId=GROUPIDSTRING&isPreviousIFrame= indicates not in queue
  52. * preview?isPreviousIFrame= indicates we are in the queue pipeline */
  53. var hitExternalNextLink = $('a[href^="/mturk/preview?isPreviousIFrame="][id="hitExternalNextLink"]');
  54. var sortmyhits_URL = localStorage.getItem('mtbqof_sortmyhits_URL') || DEFAULT_SORT_URL;
  55.  
  56. if (hitExternalNextLink.length > 0)
  57. { // This HIT is in the queue pipeline.
  58. if (this_URL.split('?')[0] == '/mturk/continue')
  59. {
  60. $.ajax({
  61. url: sortmyhits_URL,
  62. type: 'GET',
  63. success: function(data)
  64. {
  65. var $src = $(data);
  66. var maxpagerate = $src.find('td[class="error_title"]:contains("You have exceeded the maximum allowed page request rate for this website.")');
  67. if (maxpagerate.length == 0)
  68. {
  69. var $continue_links = $src.find('a[href^="/mturk/continue"]');
  70. var num_hits = $src.find('td[class="title_orange_text"]:contains("Results")').text().trim().split(' ')[2];
  71. var hit_rank = $continue_links.index($src.find('a[href^="'+this_URL+'"]')) + 1;
  72. if (hit_rank > 0 && num_hits > 0)
  73. {
  74. document.title = hit_rank+'/'+num_hits+' '+document.title;
  75. }
  76.  
  77. var first_queue_URL = $continue_links.eq(0).attr('href');
  78. if (first_queue_URL)
  79. {
  80. if (this_URL == first_queue_URL)
  81. {
  82. var second_queue_URL = $continue_links.eq(1).attr('href');
  83. if (second_queue_URL)
  84. {
  85. hitExternalNextLink.attr('href', second_queue_URL);
  86. }
  87. else
  88. {
  89. /* No more HITs left when we last checked but it's possible one arrived afterwards,
  90. * so redirect to the first HIT in the queue if it is there. */
  91. hitExternalNextLink.attr('href', '/mturk/myhits?first');
  92. }
  93. }
  94. else
  95. {
  96. hitExternalNextLink.attr('href', first_queue_URL);
  97. }
  98. }
  99. }
  100. else
  101. {
  102. hitExternalNextLink.attr('href', ON_ERROR_REDIRECT_URL);
  103. }
  104. },
  105. error: function(xhr, status, error)
  106. {
  107. hitExternalNextLink.attr('href', ON_ERROR_REDIRECT_URL);
  108. },
  109. timeout: TIMEOUT_TIMELIMIT
  110. });
  111. }
  112. else if (this_URL == '/mturk/submit' || this_URL.split('?')[0] == '/mturk/return')
  113. { // Next HIT after a QuestionForm HIT was submitted or next HIT after a HIT was returned.
  114. /* This section of code should only run on HITs that are in the pipeline. Since this code
  115. doesn't modify the document, it might be tempting to run this section at document-start.
  116. That is not possible because we need the content to be ready so that hitExternalNextLink
  117. is available to determine whether we are in the pipeline or not. */
  118. $.ajax({
  119. url: sortmyhits_URL,
  120. type: 'GET',
  121. success: function(data)
  122. {
  123. var $src = $(data);
  124. var maxpagerate = $src.find('td[class="error_title"]:contains("You have exceeded the maximum allowed page request rate for this website.")');
  125. if (maxpagerate.length == 0)
  126. {
  127. var first_queue_URL = $src.find('a[href^="/mturk/continue"]').eq(0).attr('href');
  128. if (first_queue_URL)
  129. {
  130. window.location.replace(first_queue_URL);
  131. }
  132. }
  133. else
  134. {
  135. window.location.replace(ON_ERROR_REDIRECT_URL);
  136. }
  137. },
  138. error: function(xhr, status, error)
  139. {
  140. window.location.replace(ON_ERROR_REDIRECT_URL);
  141. },
  142. timeout: TIMEOUT_TIMELIMIT
  143. });
  144. }
  145. }
  146. else if (this_URL == '/mturk/myhits?first' || (this_URL.split('?')[0] == '/mturk/continue' && $('span[id="alertboxHeader"]:contains("You have already")').length > 0))
  147. { // When we see this URL jump to the first HIT in the queue. This is useful URL to bookmark. Or if you've already completed or returned a HIT then jump to the first HIT in the queue.
  148. var first_queue_URL = $('a[href^="/mturk/continue"]').eq(0).attr('href');
  149. if (first_queue_URL)
  150. {
  151. window.location.replace(first_queue_URL);
  152. }
  153. }
  154. else if (this_URL.split('?')[0] == '/mturk/sortmyhits')
  155. { // Modify and save the queue sort URL so the code can see all 25 (sometimes 26) on the same page to determine rank.
  156. localStorage.setItem('mtbqof_sortmyhits_URL', this_URL.replace("%2310%23", "%2326%23")); // a maximum of 26 HITs on a single page
  157. }
  158. // else it's a submit link but not inside the queue pipeline, so do nothing
  159. });