Wanikani: Back to back

Makes reading and meaning appear back to back in reviews and lessons

  1. // ==UserScript==
  2. // @name Wanikani: Back to back
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3.19
  5. // @description Makes reading and meaning appear back to back in reviews and lessons
  6. // @author Kumirei
  7. // @match https://www.wanikani.com/*
  8. // @match https://preview.wanikani.com/*
  9. // @exclude https://www.wanikani.com/subject-lessons/*
  10. // @require https://greasyfork.org/scripts/462049-wanikani-queue-manipulator/code/WaniKani%20Queue%20Manipulator.user.js?version=1426722
  11. // @license MIT
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. ;(function () {
  16. // Globals
  17. const { wkof, wkQueue } = window
  18.  
  19. // Script info
  20. const script_name = 'Back 2 Back'
  21. const script_id = 'back2back'
  22.  
  23. // Make sure WKOF is installed
  24. confirm_wkof(script_name).then(start)
  25.  
  26. // Listen for page changes
  27. window.addEventListener(`turbo:before-render`, start)
  28.  
  29. // Startup
  30. function start() {
  31. wkof.include('Menu,Settings')
  32. wkof.ready('Menu,Settings').then(load_settings).then(install)
  33. }
  34.  
  35. // Installs script functions on page
  36. function install() {
  37. install_menu()
  38. run()
  39. }
  40.  
  41. function run() {
  42. const settings = wkof.settings[script_id]
  43. if (settings.behavior !== 'none') settings.behavior = 'always' // Map unavailable behavior modes to "always"
  44. if (settings.behavior === 'always') wkQueue.completeSubjectsInOrder = true
  45. if (settings.prioritize !== 'none') wkQueue.questionOrder = `${settings.prioritize}First`
  46. }
  47.  
  48. /* ----------------------------------------------------------*/
  49. // WKOF setup
  50. /* ----------------------------------------------------------*/
  51.  
  52. // Makes sure that WKOF is installed
  53. async function confirm_wkof() {
  54. if (!wkof) {
  55. let response = confirm(
  56. `${script_name} requires WaniKani Open Framework.\nClick "OK" to be forwarded to installation instructions.`,
  57. )
  58. if (response) {
  59. window.location.href =
  60. 'https://community.wanikani.com/t/instructions-installing-wanikani-open-framework/28549'
  61. }
  62. return
  63. }
  64. }
  65.  
  66. // Load WKOF settings
  67. function load_settings() {
  68. const defaults = {
  69. prioritize: 'none',
  70. behavior: 'always',
  71. }
  72. return wkof.Settings.load(script_id, defaults)
  73. }
  74.  
  75. // Installs the options button in the menu
  76. function install_menu() {
  77. const config = {
  78. name: script_id,
  79. submenu: 'Settings',
  80. title: script_name,
  81. on_click: open_settings,
  82. }
  83. wkof.Menu.insert_script_link(config)
  84. }
  85.  
  86. // Opens settings dialogue when button is pressed
  87. function open_settings() {
  88. let config = {
  89. script_id: script_id,
  90. title: script_name,
  91. on_save: run,
  92. content: {
  93. behavior: {
  94. type: 'dropdown',
  95. default: 'always',
  96. label: 'Behavior',
  97. hover_tip:
  98. "Choose whether to:\n1. Keep repeating the same question until you get it right\n2. Disable any reordering, falling back to WaniKani's default behavior",
  99. // hover_tip:
  100. // "Choose whether to:\n1. Keep repeating the same question until you get it right\n2. Only keep the item if you answered the first question correctly\n3. Make it so that you have to answer both questions correctly back to back\n4. Disable any reordering, falling back to WaniKani's default behavior",
  101. content: {
  102. always: 'Repeat until correct',
  103. // correct: 'Shuffle incorrect',
  104. // true: 'True Back To Back',
  105. disabled: 'Disabled',
  106. },
  107. },
  108. prioritize: {
  109. type: 'dropdown',
  110. label: 'Prioritize',
  111. default: 'reading',
  112. content: { none: 'None', reading: 'Reading', meaning: 'Meaning' },
  113. },
  114. },
  115. }
  116. let dialog = new wkof.Settings(config)
  117. dialog.open()
  118. }
  119. })()