Wanikani Lightning Mode

Eliminates second Enter or Click for correct review answers.

目前為 2018-01-28 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Wanikani Lightning Mode
  3. // @namespace wklightning
  4. // @description Eliminates second Enter or Click for correct review answers.
  5. // @include https://www.wanikani.com/review/session*
  6. // @include https://www.wanikani.com/lesson/session*
  7. // @version 1.0.6
  8. // @author Robin Findley
  9. // @copyright 2018+, Robin Findley
  10. // @license MIT; http://opensource.org/licenses/MIT
  11. // @run-at document-end
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. //==[ History ]======================================================
  16. // 1.0.6 - Fixed issue with proceeding at end of lesson group.
  17. // 1.0.5 - Added support for lessons.
  18. // 1.0.4 - Added option to show item info when slightly off or multi-answer.
  19. // 1.0.3 - Fix to restore SRS status popup. Thanks to @ccookf contributions!
  20. // 1.0.2 - Enable lightning mode by default for new installs.
  21. // 1.0.1 - Added option to not auto-advance if answer is slightly off.
  22. // Added option to not auto-advance if item has multiple answers.
  23. // 1.0.0 - Initial release.
  24. //===================================================================
  25.  
  26. //==[ Settings ]=====================================================
  27. // The following script configuration variables are available. You
  28. // can enable them by pasting the corresponding line in the javascript
  29. // console (press F12 in most browsers to open the console), or by
  30. // removing the "//" before the corresponding "localStorage" line
  31. // below. The setting will be saved in storage.
  32. // To remove a setting from storage, enter the following line in the
  33. // javascript console, with corresponding setting name replaced:
  34. // delete localStorage.wkdpp_setting_name;
  35. //-------------------------------------------------------------------
  36. //
  37. // Halt if answer is slightly off.
  38. // localStorage.wklightning_halt_slightly_off = 1;
  39. //
  40. // Halt if answer has multiple meanings.
  41. // localStorage.wklightning_halt_multiple = 1;
  42. //
  43. // Open item info when halting for "slightly off" or "multiple meanings".
  44. // localStorage.wklightning_info_on_halt = 1;
  45. //===================================================================
  46.  
  47. wklightning = {};
  48.  
  49. (function(gobj){
  50.  
  51. var lightning = false;
  52. var observer;
  53. var ignore;
  54.  
  55. function addStyle(css) {
  56. var head, style;
  57. head = document.getElementsByTagName('head')[0];
  58. if (head) {
  59. style = document.createElement('style');
  60. style.setAttribute('type', 'text/css');
  61. style.textContent = css;
  62. head.appendChild(style);
  63. return style;
  64. }
  65. return null;
  66. }
  67.  
  68. //-------------------------------------------------------------------
  69. // Process stored configuration settings.
  70. //-------------------------------------------------------------------
  71. function process_settings() {
  72. function value_or_default(value, dflt) {return (value===undefined ? dflt : value);}
  73.  
  74. // Halt if answer is slightly off.
  75. gobj.halt_slightly_off = value_or_default(localStorage.wklightning_halt_slightly_off, 0);
  76.  
  77. // Halt if answer has multiple meanings.
  78. gobj.halt_multiple = value_or_default(localStorage.wklightning_halt_multiple, 0);
  79.  
  80. // Halt if answer has multiple meanings.
  81. gobj.info_on_halt = value_or_default(localStorage.wklightning_info_on_halt, 0);
  82. }
  83.  
  84. //-------------------------------------------------------------------
  85. // main() - Runs after page is done loading.
  86. //-------------------------------------------------------------------
  87. function main() {
  88. process_settings();
  89. addStyle(
  90. '#lightning-mode.active {color:#ff0; opacity:1.0;}'+
  91. '#answer-form fieldset.WKLM_warn button, #answer-form fieldset.WKLM_warn input[type=text], #answer-form fieldset.WKLM_warn input[type=text]:disabled {background-color:#fa2 !important;}'
  92. );
  93.  
  94. lightning = localStorage.getItem('lightning');
  95. lightning = (lightning !== 'false');
  96. $('#summary-button').append('<a id="lightning-mode" href="#"'+(lightning?' class="active"':'')+'><i class="icon-bolt"></i></a>');
  97. $('#lightning-mode').click(function() {
  98. lightning = !lightning;
  99. console.log('Lightning mode '+(lightning?'en':'dis')+'abled!');
  100. localStorage.setItem('lightning', lightning);
  101. $(this).toggleClass('active', lightning);
  102. return false;
  103. });
  104. ignore = false;
  105. observer = new MutationObserver(function(mutations) {
  106. mutations.forEach(function(mutation) {
  107. if (!lightning || ignore) return;
  108. switch (mutation.target.className) {
  109. case 'correct':
  110. var exception = $('#answer-exception');
  111. var advance = true;
  112. if (exception.length > 0) {
  113. var msg = exception.text();
  114. // Show the item info.
  115. if (msg.match('multiple') !== null && gobj.halt_multiple) {
  116. advance = false;
  117. } else if (msg.match('answer was a bit off') !== null && gobj.halt_slightly_off) {
  118. advance = false;
  119. }
  120. }
  121. // Auto-advance.
  122. if (advance) {
  123. if ($('#lesson-ready-continue:visible').length > 0) {
  124. var srs_notice = $('#question-type .srs').detach();
  125. $('#answer-form button').click();
  126. setTimeout(function(){
  127. $('#question-type').append(srs_notice);
  128. setTimeout(function(){
  129. $('#question-type .srs').fadeOut(function(){this.remove();});
  130. },1500);
  131. },100);
  132. }
  133. } else {
  134. $("#answer-form fieldset").addClass("WKLM_warn");
  135. if (gobj.info_on_halt) {
  136. var ae = $('#answer-exception').remove();
  137. var ac = $('#additional-content');
  138. $('#additional-content #option-item-info').click();
  139. ac.append(ae);
  140. ac.attr('style','z-index:1000');
  141. }
  142. }
  143. break;
  144. case 'warning':
  145. case '':
  146. break;
  147. default:
  148. $('#additional-content #option-item-info').click();
  149. break;
  150. }
  151.  
  152. // Ignore additional changes for 100ms
  153. ignore = true;
  154. setTimeout(function(){ignore = false;}, 100);
  155. });
  156. });
  157. observer.observe(document.querySelector('#answer-form fieldset'), {attributes: true, subtree: true, attributeFilter: ['class']});
  158. }
  159.  
  160. //-------------------------------------------------------------------
  161. // Run main() upon load.
  162. //-------------------------------------------------------------------
  163. if (document.readyState === 'complete')
  164. main();
  165. else
  166. window.addEventListener("load", main, false);
  167.  
  168. }(wklightning));

QingJ © 2025

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