Wanikani: Level Duration

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

Από την 16/05/2018. Δείτε την τελευταία έκδοση.

// ==UserScript==
// @name         Wanikani: Level Duration
// @namespace    Wanikani: Level Duration
// @version      2.1.0.
// @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;
		}
		//if it's installed then do the stuffs
		else {
				wkof.include('Apiv2');
				wkof.ready('Apiv2').then(fetch_data);
		}

		//fetches and processes the level's unlock date
		function fetch_data(data) {
				wkof.Apiv2.fetch_endpoint('/level_progressions').then(function(data) {
						var date = data.data[data.total_count-1].data.unlocked_at;
						var days_passed = (Date.now() - Date.parse(date))/(1000*60*60*24);
						if (days_passed > 10) {days_passed = Math.round(days_passed);}
						$('head').append('<style>' +
										 '    .dropdown.levels > a, .nav li.reviews a {padding-bottom: 0 !important;}' +
										 '    .level-duration {' +
										 '        text-align: center;' +
										 '        color: #999 !important;' +
										 '        font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;' +
										 '        text-shadow: 0 1px 0 #ffffff;' +
										 '        margin-top: -2px;' +
										 '    }' +
										 '</style>');
						var target = ".dropdown.levels";
						if ($(window).width() <= 979) {target = ".nav li.reviews a";}
						$(target).closest('li').append('<div class="level-duration">' + Math.round(10*days_passed)/10 + ' days on level</div>');
				});
		}
})();