mmmturkeybacon Scroll To Workspace

When a HIT has been accepted, this script scrolls the mturk workspace to the

2014-07-08 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

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