Memrise Timer Toggle

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==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);