WaniKani Fast Abridged Wrong/Multiple Answer

try to take over the world!

当前为 2018-04-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WaniKani Fast Abridged Wrong/Multiple Answer
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.2
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://www.wanikani.com/review/session
  8. // @match https://www.wanikani.com/
  9. // @match https://www.wanikani.com/dashboard
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. window.wk_fawa = {};
  14.  
  15. var wrongCountFAWA;
  16. (function(global) {
  17. 'use strict';
  18. // Hook into App Store
  19. try { $('.app-store-menu-item').remove(); $('<li class="app-store-menu-item"><a href="https://community.wanikani.com/t/there-are-so-many-user-scripts-now-that-discovering-them-is-hard/20709">App Store</a></li>').insertBefore($('.navbar .dropdown-menu .nav-header:contains("Account")')); window.appStoreRegistry = window.appStoreRegistry || {}; window.appStoreRegistry[GM_info.script.uuid] = GM_info; localStorage.appStoreRegistry = JSON.stringify(appStoreRegistry); } catch (e) {}
  20.  
  21. if (!window.wkof) {
  22. alert('SRS Grid requires Wanikani Open Framework.\nYou will now be forwarded to installation instructions.');
  23. window.location.href = 'https://community.wanikani.com/t/instructions-installing-wanikani-open-framework/28549';
  24. return;
  25. }
  26.  
  27. var settings_dialog;
  28. var defaults = {
  29. alwaysShow: false,
  30. alwaysShowOnlyMultiple: false,
  31. dontShowWrong: false
  32. };
  33.  
  34. if(localStorage.getItem("wkFastWrongAlwaysShow") != null){
  35. defaults = {
  36. alwaysShow: localStorage.getItem("wkFastWrongAlwaysShow"),
  37. alwaysShowOnlyMultiple: localStorage.getItem("wkFastWrongAlwaysShowOnlyMultiple"),
  38. dontShowWrong: localStorage.getItem("wkFastWrongDontShowWrong")
  39. };
  40. localStorage.removeItem("wkFastWrongAlwaysShow");
  41. localStorage.removeItem("wkFastWrongAlwaysShowOnlyMultiple");
  42. localStorage.removeItem("wkFastWrongDontShowWrong");
  43. }
  44. wrongCountFAWA = $.jStorage.get("wrongCount");
  45. if(window.location.href == "https://www.wanikani.com" || window.location.href == "https://www.wanikani.com/dashboard"){
  46. wkof.include('Apiv2, Menu, Settings');
  47. wkof.ready('Menu').then(install_menu);
  48. wkof.ready('Settings').then(install_settings);
  49. } else {
  50. wkof.include('Apiv2, Settings');
  51. wkof.ready('Settings').then(install_settings).then(function(){
  52. $('#user-response').after("<input id='lblCorrect' type='text' style='display: none;' disabled/>");
  53. $.jStorage.listenKeyChange('currentItem', function (key, action) {
  54. if (action === 'updated') {
  55. $('#lblCorrect').val('').css('display','none');
  56. }
  57. });
  58. $.jStorage.listenKeyChange('questionCount', function (key, action) {
  59. if(wrongCountFAWA != $.jStorage.get("wrongCount"))
  60. {
  61. wrongCountFAWA = $.jStorage.get("wrongCount");
  62. if(wkof.settings.fawa.dontShowWrong != "1"){
  63. showCorrect(0);
  64. }
  65. }
  66. else {
  67. if (action === 'updated' && $.jStorage.get("questionCount") > 0 && wkof.settings.fawa.alwaysShow == "1") {
  68. showCorrect(1);
  69. }
  70. }
  71. });
  72. });
  73. }
  74.  
  75. function install_menu() {
  76. wkof.Menu.insert_script_link({
  77. script_id: 'fawa',
  78. name: 'fawa',
  79. submenu: 'Settings',
  80. title: 'Fast Abridged Wrong/Multiple Answer',
  81. on_click: open_settings
  82. });
  83. }
  84. function open_settings() {
  85. settings_dialog.open();
  86. }
  87. function install_settings() {
  88. settings_dialog = new wkof.Settings({
  89. script_id: 'fawa',
  90. name: 'fawa',
  91. title: 'Fast Abridged Wrong/Multiple Answer',
  92. on_save: process_settings,
  93. settings: {
  94. 'alwaysShow': {type:'checkbox',label:'Always Show Correct Answers',default:defaults.alwaysShow},
  95. 'alwaysShowOnlyMultiple': {type:'checkbox',label:'&nbsp;&nbsp;&nbsp;(Only if multiple answers)',default:defaults.alwaysShowOnlyMultiple},
  96. 'dontShowWrong': {type:'checkbox',label:'&nbsp;&nbsp;&nbsp;(Don\'t show wrongs)',default:defaults.dontShowWrong}
  97. }
  98. });
  99. settings_dialog.load().then(function(){
  100. wkof.settings.fawa = $.extend(true, {}, defaults,wkof.settings.fawa);
  101. settings_dialog.save();
  102. });
  103. }
  104. function process_settings(){
  105. settings_dialog.save();
  106. console.log('Settings saved!');
  107. }
  108.  
  109. function showBar(mode){
  110. $('#lblCorrect').css('display','block');
  111. }
  112.  
  113. function showCorrect(mode){
  114. switch($('#question-type h1').text().toLowerCase()){
  115. case "vocabulary reading":
  116. if(mode === 1 && wkof.settings.fawa.alwaysShowOnlyMultiple == "1" && $.jStorage.get("currentItem").kana.length === 1) return;
  117. showBar(mode);
  118. $('#lblCorrect').val($.jStorage.get("currentItem").kana.join(", "));
  119. break;
  120. case "vocabulary meaning":
  121. case "kanji meaning":
  122. case "radical name":
  123. if(mode === 1 && wkof.settings.fawa.alwaysShowOnlyMultiple == "1" && $.jStorage.get("currentItem").en.length === 1) return;
  124. showBar(mode);
  125. $('#lblCorrect').val($.jStorage.get("currentItem").en.join(", "));
  126. break;
  127. case "kanji reading":
  128. switch($.jStorage.get("currentItem").emph.toLowerCase()){
  129. case "onyomi":
  130. if(mode === 1 && wkof.settings.fawa.alwaysShowOnlyMultiple == "1" && $.jStorage.get("currentItem").on.length === 1) return;
  131. showBar(mode);
  132. $('#lblCorrect').val($.jStorage.get("currentItem").on.join(", "));
  133. break;
  134. case "kunyomi":
  135. if(mode === 1 && wkof.settings.fawa.alwaysShowOnlyMultiple == "1" && $.jStorage.get("currentItem").kun.length === 1) return;
  136. showBar(mode);
  137. $('#lblCorrect').val($.jStorage.get("currentItem").kun.join(", "));
  138. break;
  139. }
  140. break;
  141. }
  142. }
  143.  
  144. })(window.wk_fawa);