WK Auto Commit

Auto commit for Wanikani

当前为 2016-01-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WK Auto Commit
  3. // @namespace WKAUTOCOMMIT
  4. // @version 0.2
  5. // @description Auto commit for Wanikani
  6. // @author Johannes Mikulasch
  7. // @match http://www.wanikani.com/review/session*
  8. // @match https://www.wanikani.com/review/session*
  9. // @grant none
  10. // @run-at document-end
  11. // @license
  12. // ==/UserScript==
  13.  
  14. /*
  15. * WK Auto Commit
  16. * If you typed in the correct answer then it is automatically commited.
  17. * Therefore, you have to use the 'enter' key way less than before.
  18. *
  19. *
  20. * Version 0.2
  21. * Makes script work with Greasemonkey and Firefox
  22. * Version 0.1
  23. * Initial version
  24. *
  25. */
  26.  
  27.  
  28. /* jshint -W097 */
  29. 'use strict';
  30.  
  31. var activated = true;
  32. var click_threshold = 600;
  33.  
  34. var toggle = function () {
  35. if (activated) {
  36. // Deactivates WK Auto Commit mode
  37. $("#WKAUTOCOMMIT_button").prop('title', "Switch auto commit on");
  38. $("#WKAUTOCOMMIT_button").css({"opacity":"0.5"});
  39. $("#WKAUTOCOMMIT_button").text("Auto Commit is off");
  40. activated = false;
  41. } else {
  42. // Activates WK Auto Commit mode
  43. $("#WKAUTOCOMMIT_button").prop('title', "Switch auto commit off");
  44. $("#WKAUTOCOMMIT_button").css({"opacity":"1.0"});
  45. $("#WKAUTOCOMMIT_button").text("Auto Commit is on");
  46. activated = true;
  47. }
  48. };
  49.  
  50. var sanitize = function (str1) {
  51. var str2 = str1.replace(/\s/g, ''); // Removes Whitespaces
  52. str2 = str2.toLowerCase();
  53. return str2;
  54. };
  55.  
  56. var commit = function () {
  57. $("#answer-form form button").click();
  58. setTimeout(function(){ $("#answer-form form button").click();}, click_threshold);
  59. };
  60.  
  61. var check_input = function () {
  62. var currentItem = $.jStorage.get("currentItem");
  63. var currentquestiontype = $.jStorage.get("questionType");
  64. var currentresponse = $("#user-response").val();
  65. var currentitem_response = null;
  66.  
  67. // Get possible responses from current item depending on the task (reading or meaning)
  68. if (currentquestiontype === "meaning") {
  69. currentitem_response = currentItem.en;
  70. if (currentItem.syn) {
  71. currentitem_response = currentitem_response.concat(currentItem.syn);
  72. }
  73. } else if (currentquestiontype === "reading") {
  74. if (currentItem.voc) { // Vocab word
  75. currentitem_response = currentItem.kana;
  76. } else if (currentItem.emph === 'kunyomi') { // Kanji: Kun reading
  77. currentitem_response = currentItem.kun;
  78. } else if (currentItem.emph === 'onyomi') { // Kanji: On reading
  79. currentitem_response = currentItem.on;
  80. } else {
  81. console.log("WK Auto Commit: Could not find response");
  82. }
  83. }
  84.  
  85. for (var i in currentitem_response) {
  86. if (sanitize(currentresponse) === sanitize(currentitem_response[i])) {
  87. commit();
  88. }
  89. }
  90. };
  91.  
  92. var register_check_input = function () {
  93. $("#user-response").on("keyup", function (event) {
  94. if (activated) {
  95. check_input();
  96. }
  97. });
  98. };
  99.  
  100. var addButtons = function () {
  101. $("<div />", {
  102. id : "WKAUTOCOMMIT_button",
  103. title : "Toggle Auto Commit Mode",
  104. })
  105. .text("Auto Commit is on")
  106. .css({"background-color":"#C55"})
  107. .css({"opacity":"1"})
  108. .css({"display":"inline-block"})
  109. .css({"font-size":"0.8125em"})
  110. .css({"color":"#FFF"})
  111. .css({"cursor":"pointer"})
  112. .css({"padding":"10px"})
  113. .css({"vertical-align":"bottom"})
  114. .on("click", toggle)
  115. .prependTo("footer");
  116. };
  117.  
  118. var init = function () {
  119. console.log('WK Auto Commit (a plugin for Wanikani): Initialization started');
  120. addButtons();
  121. register_check_input();
  122. console.log('WK Auto Commit: Initialization ended');
  123. };
  124.  
  125. $(function(){
  126. init();
  127. });

QingJ © 2025

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