[MTurk Worker] No HIT Reloader

Reloads pages automatically if no HIT is loaded for provided Group Ids

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         [MTurk Worker] No HIT Reloader
// @namespace    https://github.com/Kadauchi
// @version      2.1.1
// @description  Reloads pages automatically if no HIT is loaded for provided Group Ids
// @author       Kadauchi
// @icon         http://i.imgur.com/oGRQwPN.png
// @include      https://worker.mturk.com/*
// @grant        GM_getTab
// @grant        GM_saveTab
// ==/UserScript==

(function () {
    GM_getTab((tab) => {
        const gid = location.href.match(/projects\/([A-Z0-9]+)/) ? location.href.match(/projects\/([A-Z0-9]+)/)[1] : null;
        const gids = localStorage.NHR_gids ? JSON.parse(localStorage.NHR_gids) : {};

        let timeout = null;

        const reloader = () => {
            if (!gid && gids[tab.gid]) {
                timeout = setTimeout(() => {
                    window.location.replace(`https://worker.mturk.com/projects/${tab.gid}/tasks/accept_random`);
                }, 500);
            }
            else {
                clearTimeout(timeout);
            }
        };

        if (location.href.indexOf(`https://worker.mturk.com/projects`) !== -1) {
            if (gid) {
                tab.gid = gid;
            }
            else {
                reloader();
            }

            if (tab.gid) {
                const button = document.createElement(`button`);
                button.title = `Auto Reload ${tab.gid} If No HIT?`;
                button.className = `m-l-sm fa fa-refresh btn ${gids[tab.gid] ? `btn-success` : `btn-default`}`;
                button.addEventListener(`click`, (event) => {
                    button.classList.toggle(`btn-success`);
                    button.classList.toggle(`btn-default`);

                    gids[tab.gid] = button.classList.contains(`btn-success`);
                    localStorage.NHR_gids = JSON.stringify(gids);

                    reloader();
                });

                document.getElementsByClassName(`navbar-content`)[0].appendChild(button);
            }
        }
        else {
            tab.gid = undefined;
        }

        GM_saveTab(tab);
    });
})();