Memrise Timer Toggle

Adds a button to toggle the timer on/off. You can also click on the timer to pause/unpause the timer.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name           Memrise Timer Toggle
// @description    Adds a button to toggle the timer on/off. You can also click on the timer to pause/unpause the timer.
// @match          http://*.memrise.com/*
// @match          https://*.memrise.com/*
// @run-at         document-end
// @version        1.1.1
// @grant          none
// @namespace      https://greasyfork.org/users/213706
// ==/UserScript==

// Based on https://gist.github.com/AntonioRigo/fae2536dbf5b7626c509102b2226353c/memrise-timer-toggle.user.js
if(typeof unsafeWindow == "undefined") {
  unsafeWindow = window;
}

var onLoad = function() {
  	var leftArea = document.getElementById("left-area");
		if(!leftArea) {
    	return;
    }

    // Add "pause timer" link to left area
    var pauseBtn = document.createElement('p');
    pauseBtn.innerHTML = "Pause timer";
    leftArea.appendChild(pauseBtn);

    pauseBtn.addEventListener("click", toggleTimer, false);
    document.getElementById("right-area").addEventListener("click", toggleTimer, false);

    // Toggle timer
    var pause = false;
    function toggleTimer() {
        if (pause) {
            unsafeWindow.MEMRISE.garden._events.unpause[0]();
            pauseBtn.innerHTML='Pause timer';
            pause = false;
        } else {
            unsafeWindow.MEMRISE.garden._events.pause[0]();
            pauseBtn.innerHTML='Unpause timer';
            pause = true;
        }
    }
};

window.addEventListener("load", function(){
  setTimeout(onLoad, 0);
}, false);