mmmturkeybacon Auto Reload Google IFrame On Error

Automatically reloads the iframe of a Google HIT if the "Please refresh the current page in your browser." error occurs. Adds a reload button in the top right corner of the iframe for Google HITs.

  1. // ==UserScript==
  2. // @name mmmturkeybacon Auto Reload Google IFrame On Error
  3. // @version 1.02
  4. // @description Automatically reloads the iframe of a Google HIT if the "Please refresh the current page in your browser." error occurs. Adds a reload button in the top right corner of the iframe for Google HITs.
  5. // @author mmmturkeybacon
  6. // @namespace http://userscripts.org/users/523367
  7. // @match https://www.google.com/evaluation/endor/mturk?*
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // ==/UserScript==
  12.  
  13. var RELOAD_ATTEMPTS_MAX = 3;
  14. var RELOAD_DELAY = 1000; // milliseconds
  15.  
  16. $(document).ready(function()
  17. {
  18. var button_holder = document.createElement("DIV");
  19. button_holder.style.cssText = "position: fixed; top: 0px; right: 0px; z-index: 20;";
  20. button_holder.innerHTML = '<input type="button" onclick="window.location.reload(true)" value="Reload" />';
  21. document.body.insertBefore(button_holder, document.body.firstChild);
  22.  
  23. var idx = document.location.href.indexOf('assignmentId=') + 13;
  24. var assignmentId = document.location.href.substring(idx).split('&')[0];
  25. if (assignmentId != GM_getValue('mtbgir_assignmentId', 'ASSIGNMENT_ID_NOT_AVAILABLE'))
  26. {
  27. GM_setValue('mtbgir_assignmentId', assignmentId);
  28. GM_setValue('mtbgir_reload_attempts', 0);
  29. }
  30.  
  31. var refresh_page_error = $('p:contains("Please refresh the current page in your browser.")').length > 0;
  32. var mtbgir_reload_attempts = GM_getValue('mtbgir_reload_attempts', 0);
  33. if (refresh_page_error && mtbgir_reload_attempts < RELOAD_ATTEMPTS_MAX)
  34. {
  35. GM_setValue('mtbgir_reload_attempts', mtbgir_reload_attempts+1);
  36. setTimeout(function(){window.location.reload(true);}, RELOAD_DELAY);
  37. }
  38. else if (refresh_page_error)
  39. {
  40. alert('mmmturkeybacon Auto Reload Google IFrame On Error: This page has been automatically reloaded the maximum number of times for this script.');
  41. }
  42. });