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 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();
});