mmmturkeybacon Logged Out Alert

Alerts you if you've been logged out of mturk. Your dashboard page must remain open in a tab for this script to work. This script will open a new sign in page by default. To turn off this behavior change OPEN_SIGNIN_WIN to false.

当前为 2015-12-29 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        mmmturkeybacon Logged Out Alert
// @version     1.03
// @description Alerts you if you've been logged out of mturk. Your dashboard page must remain open in a tab for this script to work. This script will open a new sign in page by default. To turn off this behavior change OPEN_SIGNIN_WIN to false.
// @author      mmmturkeybacon
// @namespace   http://userscripts.org/users/523367
// @match       https://www.mturk.com/mturk/dashboard
// @require     https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// @grant       GM_xmlhttpRequest
// ==/UserScript==

var CHECK_DELAY = 61000; // milliseconds delay between logged in check
var OPEN_SIGNIN_WIN = true;
var TIMEOUT_TIME_LIMIT = 15000;

$(document).ready(function()
{
    var alerted = false;
    function check_logged_in()
    {
        GM_xmlhttpRequest({
            method: "GET",
            url: 'https://www.mturk.com/mturk/dashboard',
            timeout: TIMEOUT_TIME_LIMIT,
            onload: function(response)
            {
                //console.log(response.finalUrl);

                if (response.finalUrl === 'https://www.mturk.com/mturk/dashboard')
                { // logged in
                    alerted = false;
                    setTimeout(check_logged_in, CHECK_DELAY);
                }
                else if (response.finalUrl.lastIndexOf('https://www.amazon.com/ap/signin?openid.ns', 0) === 0 || response.finalUrl === 'https://www.mturk.com/mturk/beginsignin')
                { // logged out
                    if (alerted == false)
                    { // only alert one time after being logged out
                        alerted = true;

                        if (OPEN_SIGNIN_WIN)
                        {
                            window.open("data:text/html,<html><title>mmmturkeybacon Logged Out Alert: You are not signed in.</title><body><center><h2>mmmturkeybacon Logged Out Alert has detected you are not signed in.</h2>You are being redirected to the <a href='https://www.mturk.com/mturk/beginsignin'>worker sign in page</a>.</center></body><script type='text/javascript'>alert('mmmturkeybacon Logged Out Alert: You are not signed in.');document.location.href='https://www.mturk.com/mturk/beginsignin'</script></html>");
                        }
                        else
                        {
                            alert('mmmturkeybacon Logged Out Alert: You are not signed in.');
                        }
                    }
                    // if a sign in is immediately followed by a sign out variable alerted won't get reset to false and another alert won't happen
                    // so reduce the delay to 5 seconds to make it less likely that we miss a sign in immediately followed by a sign out
                    setTimeout(check_logged_in, 5000);
                }
                else
                {
                    console.log(response.finalUrl);
                    alert('mmmturkeybacon Logged Out Alert: An unknown error occurred. Are you signed in? Reload page to restart this script.');
                }
            },
            onerror: function(response)
            {
                console.log(response.finalUrl);
                alert('mmmturkeybacon Logged Out Alert: An unknown error occurred. Are you signed in? Reload page to restart this script.');
            },
            ontimeout: function()
            {
                console.log(response.finalUrl);
                alert('mmmturkeybacon Logged Out Alert: Timed out. Reload page to restart this script.');
            }
        });
    }
    check_logged_in();
});