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.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        mmmturkeybacon Auto Reload Google IFrame On Error
// @version     1.02
// @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.
// @author      mmmturkeybacon
// @namespace   http://userscripts.org/users/523367
// @match       https://www.google.com/evaluation/endor/mturk?*
// @require     https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// @grant       GM_getValue
// @grant       GM_setValue
// ==/UserScript==

var RELOAD_ATTEMPTS_MAX = 3;
var RELOAD_DELAY = 1000; // milliseconds

$(document).ready(function()
{
        var button_holder = document.createElement("DIV");
        button_holder.style.cssText = "position: fixed; top: 0px; right: 0px; z-index: 20;";
        button_holder.innerHTML = '<input type="button" onclick="window.location.reload(true)" value="Reload" />';
        document.body.insertBefore(button_holder, document.body.firstChild);

        var idx = document.location.href.indexOf('assignmentId=') + 13;
        var assignmentId = document.location.href.substring(idx).split('&')[0];
        if (assignmentId != GM_getValue('mtbgir_assignmentId', 'ASSIGNMENT_ID_NOT_AVAILABLE'))
        {
            GM_setValue('mtbgir_assignmentId', assignmentId);
            GM_setValue('mtbgir_reload_attempts', 0);
        }

        var refresh_page_error = $('p:contains("Please refresh the current page in your browser.")').length > 0;
        var mtbgir_reload_attempts = GM_getValue('mtbgir_reload_attempts', 0);
        if (refresh_page_error && mtbgir_reload_attempts < RELOAD_ATTEMPTS_MAX)
        {
            GM_setValue('mtbgir_reload_attempts', mtbgir_reload_attempts+1);
            setTimeout(function(){window.location.reload(true);}, RELOAD_DELAY);
        }
        else if (refresh_page_error)
        {
            alert('mmmturkeybacon Auto Reload Google IFrame On Error: This page has been automatically reloaded the maximum number of times for this script.');
        }
});