Wanikani Open Framework [developer thread]

I just did an experiment on my test account, and the ‘review IDs’ from jStorage’s “reviewQueue” and “activeQueue” both matched the API’s subject ID.

1 Like

Man, I am seriously so sorry.
I’m thinking that some mess-up on my part in handling a promise resulted in me misunderstanding why I was seeing an undefined printout message.

I can actually pull the review items from the /review/items endpoint. I’ll double check if there was some other issue when I tried using the reviewQueue items as subject IDs – I presume it was just an issue of tired-eyes :sweat_smile:

1 Like

No problem… gotta learn somehow :slight_smile:

FYI, each time you complete an item (i.e both reading and meaning), one new item is popped from the end of “reviewQueue”, and placed at the end of “activeQueue”. So, in my experiment, I went to the review page, looked at the last item ID in “reviewQueue”. Then I answered reviews until I completed the Reading and Meaning for one item, which triggered the last item from reviewQueue to move to activeQueue and load its details. Then I looked at the end of “activeQueue” and saw which item it was (夕) and its ID (461). I then loaded the item data from the API via wkof, and they matched.

2 Likes

Whew, lad! I finally got it sorted… can you guess what my issue was based off the state of this chunk I’m debugging? :man_facepalming:

So the activeQueue and reviewQueue was full of ints, so in trying to access them through the index built by wkof I was getting a bunch of misses. If I convert the keys to strings before checking the queue, it works just fine! :grinning_face_with_smiling_eyes:

I’ll try to finish this work leveraging wkof instead of relying on the undocumented /review/items endpoint despite getting both working so far. Thank y’all a ton for helping with this! :heart:

Sidenote: there’s a section of my plugin that’s dedicated to displaying the amount of items remaining for each SRS level. I figure with all this work, I can split that off into its own separate userscript for leveraging by other userscripts. I figure I can have it subscribe to updates to the activeQueue and reviewQueue and refresh counts on events.

The actual question regarding that: if the other plugin pulls all in-review assignments with the exact same request through wkof as this plugin, will the results stay cached and shared by both plugins?

2 Likes

The arrays and indices returned by get_items() and get_index() are built per-call, but the contents (the item structures inside the array or index) are shared between all scripts. I figured scripts might modify an array without thinking about it affecting other scripts, but it was unlikely that people would modify the item data in ways that would interfere.

edit: On each call, wkof may also query the server to ask for changed item data. But it won’t check more often than once a minute unless you reload the page.

3 Likes

That would be nice. I already have this script, but I don’t have time to update it right now

1 Like

FYI to developers…
The functionality in wkof.Menu now works on the Lessons page.

2 Likes

I decided to start working on creating Typescript types for WKOF, mainly for the intellisense in VS Code, how should I go about sharing these in case anyone else wants to try them out? I’m fairly new to TS, so I’m sure they’ll be mediocre at best, but might come in handy for someone

@rfindley What is the intended use case for get_state(), set_state(), and wait_state()?

Hmm… no idea. If they’re hosted somewhere, I could link them in the top-post. I’m open to other suggestion, too. Did you have anything in mind?

They’re for any sort of signaling between scripts, or between framework and scripts.
For example:

//=====[ script1.js ]=====
function navigate(location) {
   // Load a new page, then signal our new location for any listeners.
   wkof.set_state('location', location);
}
//=====[ script2.js ]=====
wkof.wait_state('location', 'dashboard', show_banner);

function show_banner() {
}

Also, wkof.ready() uses wkof.wait_state() internally, but it assumes that the signal you are waiting for starts with “wkof.”. So, for example,

wkof.ready('my_plugin');

is simply waiting for:

wkof.set_state('wkof.my_plugin', 'ready');
1 Like

Linking in the top post sounds good. I’ll think about it some more as I get it ready. I have the bulk of it done already, but I think I need to learn some more about typing to get it decent. I’m also not sure yet how to best utilize TS for userscripts

Ah, that makes sense. I’ve been doing React recently and the word “state” got me a bit confused.

This is pretty nice


Edit: If anyone wants to try them out I have them in a folder in my Userscripts repository

3 Likes

Are you ready for me to add it to the top-post?

Actually, now that I think about it… I may have made the top-post publicly editable. Feel free to try if you’d like.

[edit: Or maybe I didn’t?? I don’t see where that can be done. Maybe my Discourse rank has dropped since I don’t spend as much time on the forums.]

2 Likes

The top post is currently a wiki, so everyone should be able to edit it. You need to be a regular to make your own post into a wiki. I have no idea if you can modify if your post is a wiki or not after you make your post a wiki then drop down to member. :grin:

2 Likes

I think I will hold off for a couple of days while I try it out and iron out any mistakes

2 Likes

Okay, let me know if you want to borrow my iron

2 Likes

@rfindley could you make the settings available (through a gear in the top left as in reviews) on the new extra study session page?

It’s on the to-do list, tentatively Wednesday. Funny thing is, it was only a couple of weeks ago that I finally added it to the Lessons page.

1 Like

Oh my, I didn’t realize it wasn’t already there

Added my typescript types to the OP. They’re not perfect, but they helped me a lot as I was making my reorder script

1 Like