Wanikani Egg Timer

Adds a timer during reviews and displays the final time afterward

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Wanikani Egg Timer
// @namespace   wkeggtimer
// @description Adds a timer during reviews and displays the final time afterward
// @include     http://www.wanikani.com/review*
// @include     https://www.wanikani.com/review*
// @version     0.4
// @author      Horus Scope
// @grant	none
// @license     GPL version 3 or later: http://www.gnu.org/copyleft/gpl.html
// ==/UserScript==

function timeStamp( inc ) {
	var prev = parseInt(window.localStorage.eggtimer,10) + inc;
	window.localStorage.eggtimer = prev;
	//  Yes, parseInt is prettier.
	var hours = Math.floor(prev / 60 / 60);
	var minutes = Math.floor( (prev - (hours*60*60)) / 60 );
	var seconds = prev - hours*60*60 - minutes*60;
	return ""
	  + (hours? hours+"h " : "")
	  + (minutes? minutes+"m " : "")
	  + (seconds? seconds+"s" : "");
}
var timeSpan; // referenced in go( )
function generate(  ) {
	var display = document.createElement('div');
	display.className = 'timerSessionDisplay'; // no style actually defined
	timeSpan = document.createElement('span');
	timeSpan.className = 'timerSessionSpan'; // no style actually defined
	timeSpan.textContent = "Last review: " + timeStamp( 0 );
	display.appendChild(timeSpan);
	return display;
}

// start counting. [or, dont]
function go( )
{
	// change behavior depending on screen [summary, reviewing now]
	if(/session$/.exec(window.location.href)) { // review/session [ reviewing now ]
		window.localStorage.eggtimer = 0; // time start
		var header = document.getElementById('summary-button'); // because easy
		var display = generate( ); // makes div object
		header.appendChild( display );

		var showHideButton = document.createElement('div');
		var footer = document.getElementsByTagName('footer');
		showHideButton.onclick = function( ) {
			var displayTimer = window.localStorage.displayTimer;
			if( displayTimer === null || typeof displayTimer === "undefined" ) {
				displayTimer = false;
			} else {
				displayTimer = (displayTimer == "true" ? false : true);
			}
			window.localStorage.displayTimer = displayTimer;
			timeSpan.style.cssText = displayTimer ? "display: inline;" : "display: none;";
			console.log("pressed");
		};
		showHideButton.style.cssText = "background-color: #003377; color: white; cursor: pointer;"
			+ "display: inline; float: left; font-size: 0.8125em; padding: 10px; vertical-align: bottom;";
		showHideButton.textContent = "Show/hide Timer";
		footer[0].appendChild( showHideButton );
		timeSpan.style.cssText = window.localStorage.displayTimer == "false" ? "display: none" : "display: inline";
		setInterval(function() {timeSpan.textContent = "Elapsed: " + timeStamp( 1 );}, 1000);
	} else { // review [ summary screen ]
		var footer = document.getElementById('last-session-date'); // makes sense
		var display = generate( );
		footer.insertBefore(display, footer.childNodes[0]); // probably float:left btw
	}
}

window.onload = go( );