// ==UserScript== // @name mmmturkeybacon Logged Out Alert // @version 1.02 // @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 // @downloadURL none // ==/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,mmmturkeybacon Logged Out Alert: You are not signed in.

mmmturkeybacon Logged Out Alert has detected you are not signed in.

You are being redirected to the worker sign in page.
"); } 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 { 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(); });