Wanikani Toggle Kanji Visibility

Adds buttons that toggle the visibility of Kanji and their readings on the Wanikani Kanji pages

  1. /* jshint esversion: 6 */
  2.  
  3. // ==UserScript==
  4. // @name Wanikani Toggle Kanji Visibility
  5. // @description Adds buttons that toggle the visibility of Kanji and their readings on the Wanikani Kanji pages
  6. // @version 1.1
  7. // @match https://www.wanikani.com/kanji*
  8. // @author Timberpile
  9. // @license MIT; http://opensource.org/licenses/MIT
  10. // @run-at document-end
  11. // @grant none
  12. // @namespace https://gf.qytechs.cn/users/955823
  13. // ==/UserScript==
  14.  
  15. // SETTINGS
  16. const hideAtBeginning = true;
  17.  
  18. // CODE
  19. (function(global) {
  20. 'use strict';
  21.  
  22. const buttons = [];
  23.  
  24. function getLevels() {
  25. for (const e of document.getElementsByClassName("page-header__title-subtext")) {
  26. if (e.textContent.startsWith("LEVELS")) {
  27. var text = e.textContent;
  28. text = text.replace("LEVELS ", "");
  29. var vals = text.split("-");
  30. if (vals.length == 2) {
  31. return vals;
  32. }
  33. }
  34. }
  35.  
  36. return [0,0];
  37. }
  38.  
  39. function onToggleKanjiClick(event) {
  40. const button = event.target;
  41. const characters = button.parentElement.getElementsByClassName("character-item__characters");
  42. const visible = !characters[0].hasAttribute("hidden");
  43.  
  44. if (visible) {
  45. for (const char of characters) {
  46. char.setAttribute("hidden", "true");
  47. }
  48. } else {
  49. for (const char of characters) {
  50. char.removeAttribute("hidden");
  51. }
  52. }
  53. }
  54.  
  55. function onToggleReadingsClick(event) {
  56. const button = event.target;
  57. const readings = button.parentElement.getElementsByClassName("character-item__info-reading");
  58. const visible = !readings[0].hasAttribute("hidden");
  59.  
  60. if (visible) {
  61. for (const reading of readings) {
  62. reading.setAttribute("hidden", "true");
  63. }
  64. } else {
  65. for (const reading of readings) {
  66. reading.removeAttribute("hidden");
  67. }
  68. }
  69. }
  70.  
  71. const levels = getLevels();
  72.  
  73. if (levels[0] <= 0) {
  74. console.error("Couldn't find out levels");
  75. return;
  76. }
  77.  
  78. for (let i = levels[0]; i <= levels[1]; i++) {
  79. const level_anchor = document.getElementById("level-" + i);
  80. if (!level_anchor) {
  81. continue;
  82. }
  83. const level_section = level_anchor.parentElement;
  84. if (!level_section) {
  85. continue;
  86. }
  87.  
  88. const kanjiButton = document.createElement("button");
  89. kanjiButton.textContent = "Toggle Kanji";
  90. kanjiButton.onclick = onToggleKanjiClick;
  91. buttons.push(kanjiButton);
  92. level_section.prepend(kanjiButton);
  93.  
  94. const readingsButton = document.createElement("button");
  95. readingsButton.textContent = "Toggle Readings";
  96. readingsButton.onclick = onToggleReadingsClick;
  97. buttons.push(readingsButton);
  98. level_section.prepend(readingsButton);
  99. }
  100.  
  101. if (hideAtBeginning) {
  102. for (const b of buttons) {
  103. b.click();
  104. }
  105. }
  106.  
  107. })(window);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址