KW Anki Mode

Anki mode on KaniWani

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        KW Anki Mode
// @namespace   mempo
// @description Anki mode on KaniWani
// @include     https://www.kaniwani.com/reviews/session
// @include     https://kaniwani.com/reviews/session
// @version     2
// @grant       none
// @require      https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js
// ==/UserScript==

console.log('/// start of Kaniwani Anki Mode');


var lightning_mode_wrong_answer = true;

 var WKANKIMODE_showAnswer = function () {
     var answer = "";
     $("div:lang(ja)").each(function(i, obj) {
         if(!obj.innerHTML.includes("<")){ // check for html tags
             // console.log(obj.innerHTML);
             answer += obj.innerHTML;
         }
     });
   // console.log("Answer: " + answer);
   $("#answer").first().val(answer);
};

 var WKANKIMODE_answerYes = function () {
   //console.log('inside answer yes');
   $("#answer + :submit").click();
};

var WKANKIMODE_answerNo = function () {
     //console.log('inside answer no');
     $("#answer").first().val("のぺ");
     $("#answer + :submit").click();
     if(lightning_mode_wrong_answer){
          $("#answer + :submit").click();
     }
};


var bindHotkeys = function () {
    $(document).on("keydown", function (event) {

        switch (event.keyCode) {
            case 32: //SPACE
                event.stopPropagation();
                event.preventDefault();

                //console.log('//// pressed space');

                WKANKIMODE_showAnswer();

                return;
                break;
            case 49: //1
                event.stopPropagation();
                event.preventDefault();

                //console.log('//// pressed 1');


                WKANKIMODE_answerYes();

                return;
                break;
            case 50: //2

                event.stopPropagation();
                event.preventDefault();

                //console.log('//// pressed 2');

                WKANKIMODE_answerNo();

                return;
                break;
        }
            
    });
};

bindHotkeys();