Wanikani Multiple Answer Input

Input multiple readings/meanings

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Wanikani Multiple Answer Input
// @namespace    mempo
// @version      1.0
// @description  Input multiple readings/meanings
// @author       Mempo
// @match        https://www.wanikani.com/review/session
// @match        http://www.wanikani.com/review/session
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    console.log("/// START OF WKMAI");
    
    $('input#user-response').on('keydown',function(event){

    if (event.keyCode === 13){ 
        //event.preventDefault();
        event.stopPropagation();
        console.log("/// WKMAI: PROPAGATION: " + event.isPropagationStopped());
        
        var WKMAI;
        var wrong = false;
        
        if($.jStorage.get("questionType")==="meaning"){
            WKMAI = ["en","syn"];
        }else{
            WKMAI = ["kana","kana"];
        }
        
        $('input#user-response')[0].value.split(/[;]|[ ]{2,}/).forEach(function(element){
            if(element !== "" &&
               $.jStorage.get('currentItem')[WKMAI[0]].indexOf(capitalize(element.trim())) === -1 && 
               $.jStorage.get('currentItem')[WKMAI[1]].indexOf(capitalize(element.trim())) === -1 ){
                console.log(element + " is wrong!");
                wrong = true;
            }
        });
        if(!wrong){
            $('input#user-response')[0].value =  $('input#user-response')[0].value.split(/[;]|[ ]{2,}/)[0];
        }
        $("#answer-form form button").click();

        
        
    }
    

  });
    
  function capitalize(str){
        return str[0].toUpperCase() + str.substr(1);   
  }
  
})();