Wanikani Egg Timer

Adds a timer during reviews and displays the final time afterward

目前為 2016-01-16 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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.1
// @author      Horus Scope
// @grant       GM_addStyle
// @grant	GM_getValue
// @grant	GM_setValue
// @license     GPL version 3 or later: http://www.gnu.org/copyleft/gpl.html
// ==/UserScript==

function timeStamp( inc = 0 ) {
	var prev = GM_getValue("eggtimer");
	prev += inc;
	GM_setValue("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( );
	display.appendChild(timeSpan);
	return display;
}

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

		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( );