[Userscript] Kaniwani Anki Mode

yeah, definitely

should work now. If it doesn’t:

  • You might be on Firefox with Greasemonkey installed. Please switch to Tampermonkey
  • You expect a button, like with WK Anki mode. There isn’t one. In this case, read the ‘How to use’ in the OP

Works! Fantastic! Many thanks.

Thank you so much!

Hello, sorry to be that person but it’s not working for me. I’m using tampermonkey on firefox.

true.

Looked into the KW code and the website has changed a lot since I published this script. It used to be easy to find the correct answer on the page itself, but now I can’t seem to find where they put it. Don’t know if we can even access it with a user script any more. Spend some time on it, but couldn’t find a solution. If you really really want Anki Mode on KW, you should ask the creators about it. Either they could build it into their website (ideally) or they could tell us how to access the correct answer to the question.

Hey Mempo, you can access the answers, the info box is visually hidden but still present.

However css class names are generated (for scoping) and are subject to be re-generated if their underlying code changes. You could get to it with tag selectors (main > div > ul etc) but I’m still re-organising the layout a bit so that would be too brittle.

I’m not crazy about adding anki mode built-in right now (other priorities to work on), I could perhaps add a few custom data-attributes or ids for you. data-anki-answer, data-anki-submit etc so you can easily select the necessary elements even if the layout/css changes though.

1 Like

Should be working now. Can you confirm?

Managed to fix it by filtering out all the “lang(ja)” and then putting the pieces together.

If that breaks in the future, I will contact you about adding a custom id. Thanks for the help!

No worries, ids would definitely be safer/easier for you - but glad it’s working :slight_smile:

How can I edit it to respond to K and L instead of 1 and 2? I’m using the irrelephant version of your script (sorry…) in WK and would like to change this script to match that. Simply changing the numbers to the letters in the script didn’t do the magic…

Oooh, does this KaniWani script still work? I thought it broke after their update. If you tell me it is still working then I’m totally ob that. I’ll get back to you.

1 Like

Works for me! :open_mouth: Interesting! And thank you so much :heart:

Ooooh, it really works, I had not realized thata @Mempo had updated it to version 2. This is good news! :slight_smile: Thanks so much for the update, Mempo! (I really should be getting back into KaniWani once again…)

After line 48 you will find code that looks like this:

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

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


                WKANKIMODE_answerYes();

                return;
                break;
            case 50: //2

You will want to change the key codes 49 and 50 to something else. If you want them to be K and L then you would use 75 and 76:

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

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


                WKANKIMODE_answerYes();

                return;
                break;
              case 76:  //key: "L" like "loser" (sorry, you are not a loser! It's all for the sake of the mnemonics)
1 Like

Thank you a lot! This helps so much :slight_smile:

1 Like

Actually, I found out something that doesn’t work in this script.
If there are multiple correct answers, it gives both answers in a row and marks it as incorrect when I press K/1. Must be because it inputs them both. I’ll just have to manually backspace the other one out… Gah, sorry for all the edits, my own stupidity just caught me by surprise. :stuck_out_tongue:

04

I think it works if you replace the part starting at line 19:

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

With this little hack:

 var firstParentEl = null;
     $("div:lang(ja)").each(function(i, obj) {
         if(!obj.innerHTML.includes("<")){ // check for html tags
             var parentEl = obj.parentNode.parentNode.parentNode;
             if(firstParentEl !=null && parentEl!=firstParentEl){
                 //workaround: submitting multiple answers seems to cause problems so we only show and submit the first one; since there can be multiple "ja" elements
                 //that are part of an answer we use the parent element to determine if we are still within the same (first) answer object already in the next one
                 return;
             }
             // console.log(obj.innerHTML);
             answer += obj.innerHTML;
             firstParentEl = parentEl;
         }
     });

But unfortunately, the furigana information doesn’t seem to be available before submitting the answer :-/
I would need that to know if my answer was truly correct. Maybe one could load it via the WaniKani API? Not sure if that would work.

1 Like

That’s true… Mostly I know the readings, so I’ll just have to deal with it. I’m helpless when it comes to coding :sweat_smile: Anyway, thank you! This’ll help a lot in any case!

1 Like

Sorry for reviving an old thread but would it be possible to add clickable buttons to this like you did with WaniKani? I’ve tried but I havent been able to essentially gut out the buttons to add the KaniWani functions in place of the old functions. I do use them semi regularly on my phone when I’m out and about and would be a bit help if it won’t take too much time.

1 Like

I‘m unfortunately not using KW anymore and a bit busy at the moment so I can’t promise anything… :confused: But if I find a few free minutes and happen to remember it, I will have a look (not at my laptop right now…).

1 Like