Panda in Milliseconds

Panda (refresh) a page in milliseconds instead of seconds

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name        Panda in Milliseconds
// @author      Miku
// @namespace   https://greatest.deepsurf.us/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
    }
}