Displays the number of days you have spent on the current level.
当前为
// ==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>');
}
})();