Wanikani: Level Duration

Displays the number of days you have spent on the current level.

目前為 2018-04-26 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Wanikani: Level Duration
// @namespace    Wanikani: Level Duration
// @version      0.2.1.
// @description  Displays the number of days you have spent on the current level.
// @author       Kumirei
// @include      https://www.wanikani.com*
// @grant        none
// ==/UserScript==

(function() {
		//check that the Wanikani Framework is installed
		if (!window.wkof) {
				alert('Wanikani: Level Duration requires Wanikani Open Framework.\nYou will now be forwarded to installation instructions.');
				window.location.href = 'https://community.wanikani.com/t/instructions-installing-wanikani-open-framework/28549';
				return;
		}
		else {
				//if it's installed then do the stuffs
				wkof.include('ItemData');
				wkof.ready('ItemData').then(fetch_items);
		}

		//get the current level's items through WKOF
		function fetch_items() {
				//config the request to return the current level's items
				var level = $('.dropdown.levels > a > span')[0].innerText;
				var config = {
						wk_items: {
								options: {assignments: true},
								filters: {level: level, item_type: 'rad, kan'}
						}
				};
				//request
				wkof.ItemData.get_items(config).then(process_items);
		}

		//find number of days since level up and attach info to header
		function process_items(items) {
				//find the earliest unlocked item on level
				var date = Date.now();
				for (var i = 0; i < items.length; i++) {
						if (!('assignments' in items[i])) {continue;}
						var unlock_date = Date.parse(items[i].assignments.unlocked_at);
						if (unlock_date < date) {
								date = unlock_date;
						}
				}
				//use data
				var days_passed = (Date.now() - date)/(1000*60*60*24);
				$('head').append('<style>' +
								 '.dropdown.levels > a {padding-bottom: 0 !important;}' +
								 '.level-duration {text-align: center; color: grey !important;}');
				$('li.dropdown.levels').append('<div class="level-duration">' + Math.round(10*days_passed)/10 + ' days on level</div>');
		}
})();