Wanikani: Level Duration

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

当前为 2018-04-26 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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>');
		}
})();