Greasy Fork is available in English.

Show Total Lesson Count - WaniKani

Changes the count of lessons on the Today's Lessons tile to show the total number of available lessons in addition to the number selected for you

As of 07/02/2024. See the latest version.

  1. // ==UserScript==
  2. // @name Show Total Lesson Count - WaniKani
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3.3
  5. // @description Changes the count of lessons on the Today's Lessons tile to show the total number of available lessons in addition to the number selected for you
  6. // @license MIT
  7. // @author LupoMikti
  8. // @match https://www.wanikani.com
  9. // @match https://www.wanikani.com/dashboard
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. /* global wkof */
  17.  
  18. let scriptId = 'show_total_lesson_count';
  19. let scriptName = 'Show Total Lesson Count';
  20. let wkBatchSize = 0;
  21. let initial_load = true;
  22. let todaysLessonsCount;
  23. let settings;
  24.  
  25. if (!window.wkof) {
  26. if (confirm(scriptName + ' requires Wanikani Open Framework.\nDo you want to be forwarded to the installation instructions?')) {
  27. window.location.href = 'https://community.wanikani.com/t/instructions-installing-wanikani-open-framework/28549';
  28. }
  29. return;
  30. }
  31.  
  32. wkof.include('Settings, Menu, Apiv2');
  33. wkof.ready('Settings, Menu, Apiv2').then(loadSettings).then(insertMenu).then(main);
  34.  
  35. function loadSettings() {
  36. wkBatchSize = wkof.user.preferences.lessons_batch_size;
  37.  
  38. let defaults = {
  39. showTotalOnly: false,
  40. setOwnPreferredDaily: false,
  41. preferredDailyAmount: wkBatchSize * 3
  42. };
  43.  
  44. return wkof.Settings.load(scriptId, defaults).then(function(wkof_settings) {settings = wkof_settings;});
  45. }
  46.  
  47. function insertMenu() {
  48. let config = {
  49. name: scriptId,
  50. submenu: 'Settings',
  51. title: scriptName,
  52. on_click: openSettings
  53. };
  54.  
  55. wkof.Menu.insert_script_link(config);
  56. }
  57.  
  58. function openSettings() {
  59. let config = {
  60. script_id: scriptId,
  61. title: scriptName,
  62. on_save: main,
  63. content: {
  64. showTotalOnly: {
  65. type: 'checkbox',
  66. label: 'Show Only Total Lesson Count',
  67. hover_tip: `Changes display between "<today's lesson count> / <total lesson count>" and just "<total lesson count>"`,
  68. default: false
  69. },
  70. setOwnPreferredDaily: {
  71. type: 'checkbox',
  72. label: 'Set Your Own Daily Lesson Count',
  73. hover_tip: `Choose whether to display the value you set as your daily lesson count or not`,
  74. default: false
  75. },
  76. preferredDailyAmount: {
  77. type: 'number',
  78. label: 'Preferred Daily Lesson Amount',
  79. hover_tip: `The number you want displayed for "Today's Lessons". Maximum of batch size * 3. NOTE: this does not actually change the number of available lessons.`,
  80. default: wkBatchSize * 3,
  81. min: 0,
  82. max: wkBatchSize * 3
  83. }
  84. }
  85. };
  86.  
  87. let dialog = new wkof.Settings(config);
  88. dialog.open();
  89. }
  90.  
  91. function getCountContainers() {
  92. let dashboardTileCountContainer = document.querySelector('.todays-lessons__count-text .count-bubble');
  93. let navBarCountContainer = document.querySelector('.lesson-and-review-count__count'); // must rely on lessons being first
  94.  
  95. if (initial_load && dashboardTileCountContainer && navBarCountContainer) {
  96. todaysLessonsCount = parseInt(dashboardTileCountContainer.textContent);
  97. initial_load = false;
  98. }
  99.  
  100. return [dashboardTileCountContainer, navBarCountContainer];
  101. }
  102.  
  103. async function main() {
  104. let summary_data = await wkof.Apiv2.get_endpoint('summary');
  105. let totalLessonCount = summary_data.lessons[0].subject_ids.length;
  106. let lessonCountContainers = getCountContainers();
  107. let todaysCountForDisplay = todaysLessonsCount;
  108.  
  109. if (lessonCountContainers.some(node => node == null)) {
  110. return;
  111. }
  112.  
  113. if (isNaN(todaysLessonsCount)) {
  114. todaysCountForDisplay = 0;
  115. }
  116. else {
  117. if (settings.setOwnPreferredDaily)
  118. todaysCountForDisplay = todaysLessonsCount - (wkBatchSize * 3 - settings.preferredDailyAmount);
  119. }
  120.  
  121. lessonCountContainers[0].textContent = settings.showTotalOnly ? totalLessonCount : todaysCountForDisplay + ' / ' + totalLessonCount;
  122. lessonCountContainers[1].textContent = todaysCountForDisplay
  123.  
  124. if (todaysCountForDisplay === 0) {
  125. // hide the start button if it is not already, TODO: disable nav bar button if it is not already
  126. let startButton = document.querySelector('.todays-lessons-button--start')
  127. if (startButton && startButton.checkVisibility()) {
  128. startButton.style['display'] = 'none';
  129. }
  130. }
  131.  
  132. // hide "Today's" subtitle
  133. let lessonSubtitle = document.querySelector('.todays-lessons__subtitle');
  134.  
  135. if (lessonSubtitle && lessonSubtitle.checkVisibility()) {
  136. lessonSubtitle.style['display'] = 'none';
  137. }
  138. }
  139. })();