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.

  1. // ==UserScript==
  2. // @name mmmturkeybacon Scroll To Workspace
  3. // @version 3.08
  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 = $('input[type="hidden"][name="isAccepted"]').length > 0;
  19. if (is_a_HIT == true)
  20. {
  21. var captcha = $('input[name="userCaptchaResponse"]').length > 0;
  22. if (captcha == false)
  23. {
  24. var workspace;
  25. var iframe = $('iframe')[0];
  26. var hit_wrapper = $('div[id="hit-wrapper"]')[0];
  27.  
  28. if (iframe)
  29. {
  30. iframe.style.minHeight = '100vh';
  31. //iframe.focus();
  32. $(window).load(function(){iframe.focus();});
  33. workspace = iframe;
  34. }
  35. else if (hit_wrapper)
  36. {
  37. /* Changing the hit-wrapper height is undesirable because it adds extra space between the end of the contents of the HIT and the submit button.
  38. * Instead, padding is added to the end of the page to ensure proper scrolling.
  39. */
  40.  
  41. // window.innerHeight == viewport height
  42. // if there is a vertical scrollbar then $(window).height() == $(document).height()
  43. // if there is not a vertical scrollbar then $(window).height() === document.documentElement.clientHeight which can be less than the viewport height
  44.  
  45. var hit_wrapper_ypos = hit_wrapper.getBoundingClientRect().top;
  46. var pad = hit_wrapper_ypos + window.innerHeight - document.documentElement.clientHeight;
  47. if (pad > 0)
  48. {
  49. $('form[name="hitForm"][method="POST"][action="/mturk/hitReview"]').parent().before('<div style="height: '+pad+'">');
  50. }
  51. workspace = hit_wrapper;
  52. }
  53.  
  54. var isAccepted = $('input[type="hidden"][name="isAccepted"][value="true"]').length > 0;
  55. if (workspace && isAccepted == true)
  56. { // HIT accepted
  57. workspace.scrollIntoView();
  58. //if (window.chrome)
  59. //{
  60. // /* This solves the problem of chrome scrolling to the last position it
  61. // * remembers. However, if a page is loaded that chrome doesn't remember
  62. // * a position for this will snap back to the top of the workspace the
  63. // * first time the user scrolls, which is not an ideal solution and why
  64. // * this is commented out.
  65. // * A timeout of 0 works, but it is jarring and looks buggy.
  66. // */
  67. // $(window).load(function(){window.onscroll = function(){ window.onscroll=null; setTimeout( function(){workspace.scrollIntoView();}, 500 ); }});
  68. //}
  69. }
  70. else if (workspace && isAccepted == false)
  71. { // previewing HIT
  72. var timer = $('span[id="theTime"][class="title_orange_text"]')[0];
  73. timer.scrollIntoView();
  74.  
  75. //if (window.chrome)
  76. //{
  77. // $(window).load(window.onscroll = function(){ window.onscroll=null; setTimeout( function(){timer.scrollIntoView();}, 500);});
  78. //}
  79. }
  80. }
  81. }
  82. });