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.

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

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

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

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

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