Memrise Timer Toggle

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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