// ==UserScript== // @name WaniKani Level Breakdown // @namespace https://github.com/domenic/wk-scripts // @version 1.0.4 // @author Domenic Denicola // @description Displays the breakdown within Apprentice and Guru levels on the dashboard // @license MIT // @homepageURL https://github.com/domenic/wk-scripts/blob/master/changelogs/level-breakdown.md // @downloadURL https://raw.githubusercontent.com/domenic/wk-scripts/master/scripts/level-breakdown.user.js // @updateURL https://raw.githubusercontent.com/domenic/wk-scripts/master/scripts/level-breakdown.user.js // @supportURL https://github.com/domenic/wk-scripts/issues // @require https://raw.githubusercontent.com/domenic/wk-scripts/master/helpers/api.js#v3 // @match https://www.wanikani.com/ // @match https://www.wanikani.com/dashboard // @run-at document-end // @grant GM_addStyle // @noframes // ==/UserScript== "use strict"; (async () => { GM_addStyle(`.dashboard section.srs-progress span.level-breakdown { display: flex; color: var(--color-srs-progress-text); font-size: var(--font-size-small); margin-block: var(--spacing-xtight); justify-content: center; }`); // Create the containers for all levels, for layout purposes, even if we don't fill them. for (const level of ["apprentice", "guru", "master", "enlightened", "burned"]) { const container = document.createElement("span"); container.className = "level-breakdown"; container.textContent = "\xA0"; // nonbreaking space, to ensure it doesn't collapse levelContainerFromName(level).querySelector(".srs-progress__stage-header").after(container); } const counts = await getCounts(); for (const [level, levelCounts] of Object.entries(counts)) { const container = levelContainerFromName(level).querySelector(".level-breakdown"); container.textContent = levelCounts.join(" / "); } })(); async function getCounts() { const results = await Promise.all([ makeAPIRequest("assignments?srs_stages=1"), makeAPIRequest("assignments?srs_stages=2"), makeAPIRequest("assignments?srs_stages=3"), makeAPIRequest("assignments?srs_stages=4"), makeAPIRequest("assignments?srs_stages=5"), makeAPIRequest("assignments?srs_stages=6") ]); const counts = results.map(result => result.total_count); const apprentice = counts.slice(0, 4); const guru = counts.slice(4, 6); return { apprentice, guru }; } function levelContainerFromName(level) { return document.querySelector(`.srs-progress__stage.srs-progress__stage--${level}`); }