[Userscript] Self-Study Quiz


:point_right: [v3.0.0] - Migrated to Wanikani Open Framework and APIv2


There are some UI issues with dragging the settings box. If you drag it up quickly, you can actually make it go above the visible part of the browser window, making it so you can’t continue to move the dialog. Resizing the dialog fixes this issue.

Also, what does the “Include this source” setting do? Is it just a namespacing type of thing?


That’s entirely jquery UI, though I might be able to do a post-drag check and correction.
I’m not totally happy with some of jquery UI’s behavior, but I also don’t want to write my own (ugh!).

Via the Open Framework, scripters can add external sources of data, like a Core10k deck, which will then have its own tab next to Wanikani in the Items section. If you want to create a preset that only quizzes you on Core10k vocab, you would uncheck the “Include this source” on the Wanikani tab, and check it on the “Core10k” tab.


I see, so it’s basically a way to add entirely different items to self quiz with your script.

Can you give an example for how I’d add a filter? I have a handful I want to add. Also, what’s your thought on best practice for bundling a bunch together versus including a separate script per additional filter?

wkof.ItemData.registry.sources.wk_items.filters.percent_filter = {
    type: 'number',
    label: 'Percent Correct',
    filter_func: percent_filter_func,
    set_options: function(options){options.review_statistics = true;},
    hover_tip: 'Filter items by accuract (in percent)'
function percent_filter_func(filter_value, item) {
    if (item.review_statistics === undefined) return false;
    var percent = item.review_statistics.percentage_correct;
    if (percent === null || percent === undefined) return false;
    if (percent < filter_value)
        return true;
        return false;

I’ll probably create a “Filter Pack” script, which will have its own [Menu -> Scripts: Settings -> Open Framework Filter Pack]. That will open a separate Settings dialog where users can check which filters they want to register, so only desired ones will appear in the Self Study Quiz settings dialog (and any other script that uses the registry).

If you want to start by just bundling filters into a single script, or start your own filter pack like I described, that would be a good start.

[edit: by the way, I created a ‘button’ filter type in case you want to make a popup dialog for setting up a multi-criteria filter. I’m not ready to delve deeper to create a cascaded ‘complex’ type yet.]


Would this just be to avoid cluttering the Self Study Quiz settings (and other script) UI? From what I could tell, each filter option is disabled by default, so including extra ones wouldn’t be harmful, just a potential eyesore. Is that right?

Sorry for all the questions, I just want to understand how it all works.


Essentially, yes. While testing, I had a handful of filters for testing specific item sets, and it was annoying having to wade through a large number of filters, even if most of them are disabled. I don’t like clutter, and I can envision there eventually being a large filter pack (especially when Core10k is implemented), so I wanted a way to hide ones I’m not using. I imagine there are other people who would want to do the same.


Looks like you’re not handling when a filter is deleted. Or rather, it looks like you are explicitly throwing an exception when that happens. I added the exact code you pasted above with the filter called percent_filter and tested it, saving a value for it in the settings. Then I replaced it with a filter I actually wanted to add. Trying to test the new filter, I get the following error:

VM1467:138 Uncaught (in promise) Error: wkof.ItemData.get_item() - Invalid filter "percent_filter"
    at apply_filters (<anonymous>:138:41)
    at <anonymous>:60:13


Yeah, I noticed that just before quitting for dinner. The preset saved in your settings is calling for a filter to be used, yet that filter doesn’t exist. The framework is properly complaining that you’re asking it to use a filter that doesn’t exist.

It looks like I need to check in the Self-Study Quiz if a filter is missing, and just remove it from the preset.


Gotcha. This could definitely use some more documentation by the way. I was having trouble getting my filter to work on first page load, and I realized it was because I didn’t have set_options: function(options) { options.assignments = true; }.


I just installed this and am using Chrome. No matter what options I choose, it takes a little while to load and then says, “No questions found!” Suggestions on what I should do or look at to resolve this?


Heh… yeah, it was only a prototype until 3 hours ago :slight_smile:


If you set the left drop-down the “All Questions” and the right one to “All Wanikani Items”, you still get “No questions found!” ?

If so, check your Javascript console for errors. Press F12 and click on the ‘Console’ tab, and post a snapshot of any errors.





Based on those errors, it looks like the ItemData module isn’t loaded.

In the Javascript console, does it say ‘undefined’ when you type the following (and press enter)?


If so, what happens when you type this?


If all else fails, you could try clearing the wkof cache:


Then refresh the page.


Yes, undefined

If so, what happens when you type this?



If all else fails, you could try clearing the wkof cache:
Then refresh the page.

No dice. I still get “no questions” and this in the console:


@rfindley Yay for minor UI bugs! Open the settings and go to the Items tab. Change the name of a preset but don’t save. Close the settings dialog, and reopen it. The name of the preset in the Edit Preset Name input has gone back to the previous/saved value. But the Presets List shows the new/unsaved value.


I missed a step in what I intended to have you do.

After this:


Try this again:


You shouldn’t get undefined anymore. If you do, then the module is having trouble loading for some reason, in which case it would help to check the Network tab to scroll back and see if there are any files that didn’t load (highlighted in red).


I’ve got a fix for this. It was introduced during the big refactoring :-/
I’ll upload after fixing the other issue (missing filter).


Ok, so now I get this:

Nothing highlighted in red in the Network tab.