Panda in Milliseconds

Panda (refresh) a page in milliseconds instead of seconds

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Panda in Milliseconds
// @author      Miku
// @namespace   https://greasyfork.org/users/2251
// @license     GNU GPL
// @description Panda (refresh) a page in milliseconds instead of seconds
// @include     https://www.mturk.com/mturk/previewandaccept*
// @version     2015.06.08
// @grant       none
// ==/UserScript==

/**
 * The purpose of this script is because most scripts capped out the panda interval at one second.
 * By temporarily disabling Page Monitor--Mturk will allow us to refresh a page faster than one second.
 * In theory millisecond refreshing should capture more HITs than that of "seconds" scripts.
 */

/**
 * Change refreshInterval's value to change the panda speed.
 *
 * Note: the value needs to be defined in milliseconds.
 */
var refreshInterval = 500; //milliseconds

/**
 * Capture the current page
 */
var currentPage = window.location.href;

/**
 * The refresh function
 */
var refresh = function() {
    window.location.reload(false);
};

/**
 * Start listening for key presses
 */
window.addEventListener('keydown', KeyCodes, true);

/**
 * Check the status of the panda for changes in key presses
 */
checkRefresh();

/**
 * Define what the key press does after being pressed
 *
 * Key ` was pressed and starts the panda
 * Key 1 was held down or pressed which stops the panda
 */
function KeyCodes(e) {
    console.log(e.keyCode);
    switch (e.keyCode) {
        case 192: // ` was pressed
            savePage();
            break;
        case 49: // 1
            deletePage();
            break;
    }

    /**
     * After a key is pressed, check if the panda should start or stop
     */
    checkRefresh();
}

/**
 * Function to save the panda status
 */
function savePage() {
    if (localStorage.getItem("reload") === null) { //check if the reload status exists
        localStorage.setItem('reload', currentPage);
    } else { //if the status does exist, delete it and save anew
        deletePage();
        localStorage.setItem('reload', currentPage);
    }
}

/**
 * Function to purge the panda status
 */
function deletePage() {
    localStorage.removeItem('reload');
}

/**
 * Main function which reads the panda status
 */
function checkRefresh() {
    reload = localStorage.getItem('reload');
    if (reload == currentPage) {
        console.log('Reloading page...');
        setTimeout(refresh, refreshInterval); //comment this out to use the other function
        //setTimeout(window.location.reload(false), refreshInterval); //this method seems broken and doesn't follow refreshInterval's value. Use this method for maximum panda speed
    }
}