DistractionType

prompt a typing test before visiting distracting sites

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

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         DistractionType
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  prompt a typing test before visiting distracting sites
// @author       dook
// @match        https://*.reddit.com/*
// @match        https://*.twitter.com/*
// @match        https://*.facebook.com/*

// @match        https://monkeytype.com/

// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_addValueChangeListener
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    //Companion script
    if (window.location.href === "https://monkeytype.com/") {
        const minWPM = 60;
        const sessionTime = 10 * 60 * 1000; //todo global session valid for 10 minutes before another test

        function GM_sendMessage(label) {
            GM_setValue(label, Array.from(arguments).slice(1));
        }

        let checkTimer = setInterval(function () {
            console.log('checking wpm...');
            const wpm = document.querySelector('#result > div:nth-child(1) > div.group.wpm > div.bottom').innerText;
            try {
                parseInt(wpm);
            } catch (e) { }

            if (wpm >= minWPM) {
                GM_sendMessage('unlock', Math.random());
                clearInterval(checkTimer); //stop checking
                window.close();
            }

        }, 3000);
    }
    else { //Blocking script (fb, twitter etc.)
        console.log('running distracted monkey');
        let locked = null; //the holy variable

        function popupwindow(url, title, w, h) {
            var left = (screen.width / 2) - (w / 2);
            var top = (screen.height / 2) - (h / 2);
            return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
        }

        //Main code, run on page load
        function run() {
            locked = true;
            document.querySelector('body').style.filter = 'blur(6px)';
            popupwindow('https://monkeytype.com/', 'Type time cunt', 800, 1200);
        }
        window.addEventListener('load', run, false);

        //disable clicks lmao
        function handler(e) {
            if (!locked) return;
            e.stopPropagation();
            e.preventDefault();
        }
        document.addEventListener("click", handler, true);

        //Get message from typing tab that the test has been finished
        GM_addValueChangeListener("unlock", () => {
            locked = false;
            document.querySelector('body').style.filter = 'none';
        });
    }
})();