Need Help: Code that grabs total kanji/vocab for a given level

Hello you beautiful coders,

I’ve wracked my feeble, noob brain trying to get my userscript to grab the total number of Kanji and Vocab for the current level. Currently my script only grabs the unlocked count.

function query_kanji() {
    wk_items: {
        options: {
            assignments: true,
        filters: {
            item_type: ["kanji"],
            level: '+0',

I’ve added the “srs: [‘locked’]” tag to filters in hopes for it to output only the locked kanji/vocab then add it to the unlocked count, but it returns 0.

I feel like this should be a simple task, but it alludes me. Any help would be appreciated, thanks!


Hi, you can look at the official documentation for wkof to find that out:

Here you can read that instead of ‘locked’ you should use -1:

And this tells you how to filter out only specific levels if you want to do that:

Hope that helps! :smile:


Appreciate the response, unfortunately I did try both before and it still returns 0.

However I was looking at a different documentation, so I will comb through the link you sent and see if I can find the solution. Thank you! :slight_smile:

1 Like

Your item type seems wrong. Should be just kan

1 Like

The Legendary Gorbit99! The script I’m making is based on yours!

kan and kanji both return the same value I’ve found. Thank you though!

Oh lol, which one?
Are you sure it’s not the function messing up? Or maybe it’s the fact that you don’t have a subscription?

Your “Better Progress Bar”, laid the groundwork for what I’m trying to do, so thank you thank you!

I’d hope it’s not the function cause it’s yours XD

I do have a yearly subscription, this is actually what made me find the bug, I leveled up and instead of it showing 0 out of (max number of kanji) it showed 0 out of 14 (which was the unlocked kanji.

@rfindley might know more about what’s going on, but this ought to work afaik

1 Like

I got it! WOooo! It wasn’t an issue with the call function but rather with the function after it!
It was an issue with calling the variable that’s mapped to the completed kanji/vocab.

You may recall:

function handle_items(items) {
let srsStages = items.filter(item => item.assignments !== undefined)
    .map(item => 
        item.assignments.passed_at !== null
            ? 5 
            : Math.min(item.assignments.srs_stage, 5));

if (srsStages.length < 0) {
    return 0;

let max = srsStages.length * 5;
let actual = srsStages.reduce((sum, x) => sum + x, 0);

The issue was with “max”, it needs to be items.length, not srsStages.length. (at least for what I’m trying to do).

Thank you, all!