Wanikani Multiple Answer Input

Input multiple readings/meanings

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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);   
  }
  
})();