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-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name mmmturkeybacon Scroll To Workspace
  3. // @version 3.06
  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 captcha = document.evaluate("//input[@name='userCaptchaResponse']", document, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
  22. if (captcha == false)
  23. {
  24. var workspace;
  25. var iframe = document.getElementsByTagName('iframe')[0];
  26. var hit_wrapper = document.evaluate("//div[@id='hit-wrapper']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  27.  
  28. if (iframe)
  29. {
  30. iframe.focus();
  31. $(window).load(function(){iframe.focus();});
  32. workspace = iframe;
  33. }
  34. else if (hit_wrapper)
  35. {
  36. workspace = hit_wrapper;
  37. }
  38.  
  39. var isAccepted = document.evaluate("//input[@type='hidden' and @name='isAccepted' and @value='true']", document, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
  40. if (workspace && isAccepted == true)
  41. { // HIT accepted
  42.  
  43. var styles = window.getComputedStyle(workspace);
  44. var padding = parseFloat(styles.paddingLeft) + parseFloat(styles.paddingRight);
  45. var percent = 100*((window.innerHeight-padding)/window.innerHeight);
  46. workspace.style.minHeight = percent+'vh';
  47.  
  48. workspace.scrollIntoView();
  49. //if (window.chrome)
  50. //{
  51. // /* This solves the problem of chrome scrolling to the last position it
  52. // * remembers. However, if a page is loaded that chrome doesn't remember
  53. // * a position for this will snap back to the top of the workspace the
  54. // * first time the user scrolls, which is not an ideal solution and why
  55. // * this is commented out.
  56. // * A timeout of 0 works, but it is jarring and looks buggy.
  57. // */
  58. // $(window).load(function(){window.onscroll = function(){ window.onscroll=null; setTimeout( function(){workspace.scrollIntoView();}, 500 ); }});
  59. //}
  60. }
  61. else if (workspace && isAccepted == false)
  62. { // previewing HIT
  63. 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;
  64. var diff_y = parseFloat(workspace.getBoundingClientRect().top) - parseFloat(timer.getBoundingClientRect().top);
  65.  
  66. var styles = window.getComputedStyle(workspace);
  67. var padding = parseFloat(styles.paddingLeft) + parseFloat(styles.paddingRight);
  68. var percent = 100*((window.innerHeight-padding-diff_y)/window.innerHeight);
  69. workspace.style.minHeight = percent+'vh';
  70.  
  71. //$('input[name="/accept"][src="/media/accept_hit.gif"][type="image"]').eq(0).closest('td')[0].scrollIntoView();
  72. timer.scrollIntoView();
  73.  
  74. //if (window.chrome)
  75. //{
  76. // $(window).load(window.onscroll = function(){ window.onscroll=null; setTimeout( function(){timer.scrollIntoView();}, 500);});
  77. //}
  78. }
  79. }
  80. }
  81. });