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. To have this script open a new sign in page when a log out is detected change OPEN_SIGNIN_WIN to true.

  1. // ==UserScript==
  2. // @name mmmturkeybacon Logged Out Alert
  3. // @version 1.04
  4. // @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. To have this script open a new sign in page when a log out is detected change OPEN_SIGNIN_WIN to true.
  5. // @author mmmturkeybacon
  6. // @namespace http://userscripts.org/users/523367
  7. // @match https://www.mturk.com/mturk/dashboard
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  9. // @grant GM_xmlhttpRequest
  10. // ==/UserScript==
  11.  
  12. var CHECK_DELAY = 61000; // milliseconds delay between logged in check
  13. var OPEN_SIGNIN_WIN = false;
  14. var TIMEOUT_TIME_LIMIT = 15000;
  15.  
  16. $(document).ready(function()
  17. {
  18. var alerted = false;
  19. function check_logged_in()
  20. {
  21. GM_xmlhttpRequest({
  22. method: "GET",
  23. url: 'https://www.mturk.com/mturk/dashboard',
  24. timeout: TIMEOUT_TIME_LIMIT,
  25. onload: function(response)
  26. {
  27. //console.log(response.finalUrl);
  28.  
  29. if (response.finalUrl === 'https://www.mturk.com/mturk/dashboard')
  30. { // logged in
  31. alerted = false;
  32. setTimeout(check_logged_in, CHECK_DELAY);
  33. }
  34. else if (response.finalUrl.lastIndexOf('https://www.amazon.com/ap/signin?openid.ns', 0) === 0 || response.finalUrl === 'https://www.mturk.com/mturk/beginsignin')
  35. { // logged out
  36. if (alerted == false)
  37. { // only alert one time after being logged out
  38. alerted = true;
  39.  
  40. if (OPEN_SIGNIN_WIN)
  41. {
  42. 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>");
  43. }
  44. else
  45. {
  46. alert('mmmturkeybacon Logged Out Alert: You are not signed in.');
  47. }
  48. }
  49. // 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
  50. // so reduce the delay to 5 seconds to make it less likely that we miss a sign in immediately followed by a sign out
  51. setTimeout(check_logged_in, 5000);
  52. }
  53. else
  54. {
  55. console.log(response.finalUrl);
  56. alert('mmmturkeybacon Logged Out Alert: An unknown error occurred. Are you signed in? Reload page to restart this script.');
  57. }
  58. },
  59. onerror: function(response)
  60. {
  61. console.log(response.finalUrl);
  62. alert('mmmturkeybacon Logged Out Alert: An unknown error occurred. Are you signed in? Reload page to restart this script.');
  63. },
  64. ontimeout: function()
  65. {
  66. console.log(response.finalUrl);
  67. alert('mmmturkeybacon Logged Out Alert: Timed out. Reload page to restart this script.');
  68. }
  69. });
  70. }
  71. check_logged_in();
  72. });