Wanikani Lightning Mode

Eliminates second Enter or Click for correct review answers.

目前為 2017-05-12 提交的版本,檢視 最新版本

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

QingJ © 2025

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