[For Userscript Authors] WK Item Info Injector

Version 3.0:

Now supports the upcoming new lesson, review, and extra study pages

WaniKani is planning to switch tomorrow to Turbo for providing the lesson, review, and extra study pages. I am not too confident that I managed to iron out all the bugs in this version. As always, please report problems right away.

// @require      https://greasyfork.org/scripts/430565-wanikani-item-info-injector/code/WaniKani%20Item%20Info%20Injector.user.js?version=1166918
2 Likes

Vocabularies in itemPage don’t have reading, though Kanji in itemPage and session pages have that just fine.

Example vocabulary on itemPage
{
    "on": "itemPage",
    "type": "vocabulary",
    "id": 4495,
    "characters": "罰金",
    "partOfSpeech": [
        "Noun"
    ],
    "meaning": [
        "A Fine",
        "Fine"
    ],
    "composition": [
        {
            "characters": "罰",
            "meaning": [
                "Penalty"
            ],
            "reading": [
                "ばつ"
            ]
        },
        {
            "characters": "金",
            "meaning": [
                "Gold"
            ],
            "reading": [
                "きん"
            ]
        }
    ],
    "hiddenSpoiler": [],
    "under": [
        "composition",
        "meaning",
        "reading",
        "examples"
    ],
    "injector": {
        "active": true
    }
}
1 Like

Thanks for the bug report. I will look into it tomorrow.

In Review pages, press F then E, expands all but Info Info injections.

I also wonder if it can be injected in collapsed state.

1 Like

I will add E functionality to the next release of Item info Injector. I hope to get it ready today after work – I had aimed for a release yesterday, but I had to stop at 2am.

Sections start off collapsed or expanded, based on their spoiler settings. If you mark your section as spoiling the reading, and then open the item info after answering a meaning question, the section will be collapsed (similar to the vanilla WK reading section). If you use .spoiling("meaning,reading"), it should always be collapsed initially.

3 Likes

I am not sure that what I’m experiencing is a bug caused specifically by this userscript or not.

I am currently updating my script WK Item Difficulty Indicator with the new turbo events. I have noticed that on the item info pages when I click from one item to the next the updating of the section I injected with this script updates perfectly. When I use the back button though to go to the previous page, somehow the section is completely missing no matter what I do.

I looked into it and it may have something to do with the turbo:before-frame-render event you are using which only triggers on page redirects caused by links not by back and forward buttons.

If the problem lies with my own userscript then I’m sorry to have bothered you, I’m just getting used to handling the turbo events :sweat_smile: Either way, thanks for your hard work!

1 Like

The list of necessary bugfixes for the next version of Item Info Injector increases with every day :sweat_smile:

3 Likes

Haha, yeah it’s always difficult having to rework something that you can’t do from scratch without missing any bugs. Don’t stress it though, take your time! It’s not like this is massively important or anything.

3 Likes

@polv, @saraqael, sorry that it took much longer than anticipated. Fixing the missing current state info and adding the E hotkey functionality was not that hard, but I was very reluctant having to go back and deal with Turbo page loading again (to catch history navigation), so I postponed my work on Item Info Injector and prioritized other scripts instead.


Version 3.1:

E hotkey toggles injected collapsible sections

I noticed that WaniKani has implemented the E behavior in a rather strange way: instead of deciding whether the hotkey should open or close sections based on the current state of the sections, it seems to use an internal variable. That means that if I manually expand all sections and hit E afterwards, it won’t do anything at all.

Instead of trying to access this internal variable, I decided to take the approach that seems more logical to me: if any (native) sections are still closed upon hitting E, all injected sections will be expanded, otherwise all will be collapsed.

Bugfix for Turbo history navigation

Dealing with Turbo history navigation turned out to be as annoying as expected: no Turbo event seems to be fired after the DOM is updated, so I used turbo:load, which I believe is the last event Turbo fires after a history navigation on item pages. await true seems to continue too fast (the DOM was still not available at that point), but setTimeout() worked. At least for history navigation between item pages. However, history navigation during lessons seems to fire no Turbo events at all! Instead, I had to use the hashchange event. And, because having two different cases is not enough, navigating from the lesson quiz back to the lessons does actually trigger turbo:before-render, so I had to make sure that sections are not injected twice.

Bugfix for partially missing currentState data

The currentState was missing some info (reading, partOfSpeech, composition, …) in some cases. This should be fixed now.

deleted outdated code (React/jStorage)

A lot of code was not needed anymore, so I was able to delete almost 400 lines of code that dealt with various React- and pre-React WaniKani versions.

// @require      https://greasyfork.org/scripts/430565-wanikani-item-info-injector/code/WaniKani%20Item%20Info%20Injector.user.js?version=1173815
3 Likes

Thank you so much! And don’t sweat it. Besides, I’ve had way longer wait times before so it’s no big deal. :bowing_man:

2 Likes

Version 3.2 (only a very small update):

Bugfix for Waterfox users

In version 3.0, I replaced [...stateSelector.under].reverse().find() with stateSelector.under.findLast(), but it seems that Waterfox is a bit behind the major browsers which adopted findLast() at the beginning of last year. For compatibility, I switched back to [...stateSelector.under].reverse().find.

// @require      https://greasyfork.org/scripts/430565-wanikani-item-info-injector/code/WaniKani%20Item%20Info%20Injector.user.js?version=1181453
1 Like

It would nice if the script supports Kana-Only vocabularies.

Currently, it doesn’t run in Review for those vocabularies, working only in item pages.


I am able to fix by installing the Injector manually (in the last order), and editing Line 265 to _currentState.type = (currentItem.subject_category || currentItem.type).toLowerCase();

Now, scripts like Anime Context and External Definition, start working.

1 Like

Thanks for reporting the problem – I have updated the script to support kana vocabulary. However, I have decided to not group kana vocabulary together with the other vocabulary. Instead, there are now four types: radical, kanji, vocabulary, and kanaVocabulary. I have updated the documentation in the first post accordingly.

Unfortunately, that means that scripts like Anime Context Sentences, that should work for vocabulary and for kanaVocabulary, have to be updated by adding “kanaVocabulary” in the forType selector.


Version 3.3:

  • Added kanaVocabulary support
// @require      https://greasyfork.org/scripts/430565-wanikani-item-info-injector/code/WaniKani%20Item%20Info%20Injector.user.js?version=1207013
2 Likes

I have an update for this script to support the new Recent Mistakes feature. I don’t have permission to update the main script but I made a forked version here (link shows my code changes):

It’s a very simple change, it just treats it the same way as Extra Study. I found I also had to increment the version number to make it work. @Sinyaven please update when you can.

In the meantime anyone should be able to edit their local script with these changes in the Tampermonkey dashboard if you want to.

1 Like

Thanks for providing an update for Item Info Injector – I did not closely follow the developments on WaniKani for the last few months, so I did not even see the new Recent Mistakes feature yet. I am a bit surprised that they gave it its own URL instead of adding it as another extra study.

This also leads me to the question: should Item Info Injector differentiate between extra study sessions and the recent mistakes session? I’m wondering if it wouldn’t be better to treat recent mistakes as just another extra study session. :thinking: I feel like it’s all the same thing and can be grouped together, and I cannot think of a situation where a userscript author would want to inject their section only in recent mistakes, but not in extra study (or vice versa).

I will think about it again in the evening, and if there are no arguments against it, I will probably just include recent mistakes in extraStudy.

1 Like

That makes sense to me, that’s probably easier :slight_smile:

1 Like

Version 3.4:

Added support for recent mistakes quiz+lessons

Thanks again @chiaracoetzee for letting me know about this WK change and providing code addressing it. I decided to put the recent mistakes quiz into the extraStudy category and the recent mistakes lessons in the lesson and lessonQuiz category.

Bugfix for review queues longer than 100 items

Thanks @theusaf for reporting this issue. I based my code on the assumption that the DOM element containing the item details would be updated when new items are loaded, but it seems that isn’t the case (I never tested it because I was too lazy to go through >100 items – I’m not using WK anymore. I also did not test the bugfix of this version, I just hope that it will work :laughing:).

Bugfix for hotkey E not expanding custom sections correctly during reviews

The hotkey functionality seems to have broken at some point. This should be fixed now.

// @require      https://greasyfork.org/scripts/430565-wanikani-item-info-injector/code/WaniKani%20Item%20Info%20Injector.user.js?version=1241826
2 Likes

The script is now broken in Lessons. Also, Lesson URLs have changed /subject-lessons/-${session_id}/...

1 Like

See the following for the full URL changes:

2 Likes

I will try to look into adapting this to the WaniKani lesson changes after I come home from work.

1 Like