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 기준 버전입니다. 최신 버전을 확인하세요.

// ==UserScript==
// @name        mmmturkeybacon Scroll To Workspace
// @version     3.06
// @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.
// @author      mmmturkeybacon
// @namespace   http://userscripts.org/users/523367
// @match       https://*.mturk.com/mturk/preview*
// @match       https://*.mturk.com/mturk/accept*
// @match       https://*.mturk.com/mturk/continue*
// @match       https://*.mturk.com/mturk/submit*
// @match       https://*.mturk.com/mturk/return*
// @require     https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// @grant       GM_log
// ==/UserScript==

$(document).ready(function ()
{   
    var is_a_HIT = document.evaluate("//input[@type='hidden' and @name='isAccepted']", document, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
    if (is_a_HIT == true)
    {
        var captcha = document.evaluate("//input[@name='userCaptchaResponse']", document, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
        if (captcha == false)
        {
            var workspace;
            var iframe = document.getElementsByTagName('iframe')[0];
            var hit_wrapper = document.evaluate("//div[@id='hit-wrapper']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

            if (iframe)
            {
                iframe.focus();
                $(window).load(function(){iframe.focus();});
                workspace = iframe;
            }
            else if (hit_wrapper)
            {
                workspace = hit_wrapper;
            }

            var isAccepted = document.evaluate("//input[@type='hidden' and @name='isAccepted' and @value='true']", document, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
            if (workspace && isAccepted == true)
            { // HIT accepted

                var styles = window.getComputedStyle(workspace);
                var padding = parseFloat(styles.paddingLeft) + parseFloat(styles.paddingRight);
                var percent = 100*((window.innerHeight-padding)/window.innerHeight);
                workspace.style.minHeight = percent+'vh';

                workspace.scrollIntoView();
                
                //if (window.chrome)
                //{
                //    /* This solves the problem of chrome scrolling to the last position it
                //     * remembers. However, if a page is loaded that chrome doesn't remember
                //     * a position for this will snap back to the top of the workspace the
                //     * first time the user scrolls, which is not an ideal solution and why
                //     * this is commented out.
                //     * A timeout of 0 works, but it is jarring and looks buggy.
                //     */
                //    $(window).load(function(){window.onscroll = function(){ window.onscroll=null; setTimeout( function(){workspace.scrollIntoView();}, 500 ); }});
                //}
            }
            else if (workspace && isAccepted == false)
            { // previewing HIT
                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;
                var diff_y = parseFloat(workspace.getBoundingClientRect().top) - parseFloat(timer.getBoundingClientRect().top);

                var styles = window.getComputedStyle(workspace);
                var padding = parseFloat(styles.paddingLeft) + parseFloat(styles.paddingRight);
                var percent = 100*((window.innerHeight-padding-diff_y)/window.innerHeight);
                workspace.style.minHeight = percent+'vh';

                //$('input[name="/accept"][src="/media/accept_hit.gif"][type="image"]').eq(0).closest('td')[0].scrollIntoView();
                timer.scrollIntoView();

                //if (window.chrome)
                //{
                //    $(window).load(window.onscroll = function(){ window.onscroll=null; setTimeout( function(){timer.scrollIntoView();}, 500);});
                //}
            }
        }
    }
});