Greasy Fork 还支持 简体中文。

mmmturkeybacon Scroll To Workspace

When a HIT has been accepted, this script scrolls the mturk workspace to the top of the window. When a HIT is being previewed, this script scrolls the 'Accept HIT' button to the top of the window, unless there is a CAPTCHA. Whenever a HIT is previewed or accepted, this script sets the iframe height equal to the browser's viewport height to ensure proper scrolling and gives focus to the iframe.

目前為 2015-04-08 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name mmmturkeybacon Scroll To Workspace
  3. // @version 3.05
  4. // @description When a HIT has been accepted, this script scrolls the mturk workspace to the top of the window. When a HIT is being previewed, this script scrolls the 'Accept HIT' button to the top of the window, unless there is a CAPTCHA. Whenever a HIT is previewed or accepted, this script sets the iframe height equal to the browser's viewport height to ensure proper scrolling and gives focus to the iframe.
  5. // @author mmmturkeybacon
  6. // @namespace http://userscripts.org/users/523367
  7. // @match https://*.mturk.com/mturk/preview*
  8. // @match https://*.mturk.com/mturk/accept*
  9. // @match https://*.mturk.com/mturk/continue*
  10. // @match https://*.mturk.com/mturk/submit*
  11. // @match https://*.mturk.com/mturk/return*
  12. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  13. // @grant GM_log
  14. // ==/UserScript==
  15.  
  16. $(document).ready(function ()
  17. {
  18. var is_a_HIT = document.evaluate("//input[@type='hidden' and @name='isAccepted']", document, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
  19. if (is_a_HIT == true)
  20. {
  21. var workspace;
  22. var iframe = document.getElementsByTagName('iframe')[0];
  23. var hit_wrapper = document.evaluate("//div [@id='hit-wrapper']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  24. var isAccepted = document.evaluate("//input[@type='hidden' and @name='isAccepted' and @value='true']", document, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
  25. var captcha = document.evaluate("//input[@name='userCaptchaResponse']", document, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
  26.  
  27. if (iframe)
  28. {
  29. iframe.height = window.innerHeight;
  30. $(window).load(function(){iframe.focus();});
  31. workspace = iframe;
  32. }
  33. else if (hit_wrapper)
  34. {
  35. /* Changing the hit_wrapper height doesn't work correctly because
  36. * this script runs before all images are are loaded. This makes it
  37. * impossible to know what the final hit_wrapper height will be and
  38. * setting the hit_wrapper height before images are loaded may
  39. * result in a hit_wrapper that is too small.
  40. * Padding is added to the end of the page to ensure proper scrolling.
  41. */
  42. var hit_wrapper_ypos = hit_wrapper.getBoundingClientRect().top;
  43. var pad = hit_wrapper_ypos+window.innerHeight-$(document).height();
  44. if (pad > 0)
  45. {
  46. var pad_div = document.createElement("div");
  47. pad_div.style.height = pad;
  48. document.body.appendChild(pad_div);
  49. }
  50. workspace = hit_wrapper;
  51. }
  52. // If isAccepted is true then there is almost certainly not a CAPTCHA but I'm not positive and I can't test for that
  53. // case, so it's better to be safe than sorry.
  54. if (captcha == false)
  55. {
  56. if (isAccepted == true && workspace)
  57. { // HIT accepted
  58. workspace.scrollIntoView();
  59. //if (window.chrome)
  60. //{
  61. // /* This solves the problem of chrome scrolling to the last position it
  62. // * remembers. However, if a page is loaded that chrome doesn't remember
  63. // * a position for this will snap back to the top of the workspace the
  64. // * first time the user scrolls, which is not an ideal solution and why
  65. // * this is commented out.
  66. // * A timeout of 0 works, but it is jarring and looks buggy.
  67. // */
  68. // $(window).load(function(){window.onscroll = function(){ window.onscroll=null; setTimeout( function(){workspace.scrollIntoView();}, 500 ); }});
  69. //}
  70. }
  71. else
  72. { // previewing HIT
  73. var timer = document.evaluate("//span[@id='theTime' and @class='title_orange_text' and @style='text-align: right;']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  74. timer.scrollIntoView();
  75. //if (window.chrome)
  76. //{
  77. // $(window).load(window.onscroll = function(){ window.onscroll=null; setTimeout( function(){timer.scrollIntoView();}, 500);});
  78. //}
  79. }
  80. }
  81. }
  82. });