This is a third-party script/app and is not created by the WaniKani team. By using this, you understand that it can stop working at any time or be discontinued indefinitely.
What is this?
Wanikani Open Framework Turbo Events is a library for script developers to include in order to simplify their workflows when dealing with Turbo Events. If you are a bit out of the loop and unfamiliar with why this is now very important, see tofugu-scott’s post here and his announcement here for more background.
Essentially, pretty much any script that was not using a library that takes care of handling the turbo events (i.e., almost all of them) behaves unexpectedly after the update. Users are forced to perform a manual refresh of the page after they navigate anywhere in order to get basic script functionality, if they’re lucky.
And that’s where this library comes in. Developers, read on.
How does it help?
It abstracts away most of the guesswork and troubleshooting for dealing with the turbo events, while allowing sufficient flexibility for most, if not all, feasible usage. Adding a basic listener for turbo:load
can be as simple as:
wkof.turbo.events.load.addListener(callbackFunction);
Or you could go a step further and easily make sure that the event happens on a certain url:
const reviewsRegex = /https:\/\/www\.wanikani\.com\/subjects\/review.*\/?$/;
wkof.turbo.events.before_render.addListener(callbackFunction, reviewsRegex);
Just be sure to include code to ensure that this is called after the Turbo Events library has been set up. This can be done conveniently with the wkof.ready(module_list)
function or wait_state(state_var, value, callback, persistent)
function. For example:
const setupTurboListener = () => wkof.turbo.on.common.dashboard(main);
wkof.ready('TurboEvents').then(setupTurboListener);
// or, this does the same as the line above
wkof.wait_state('wkof.TurboEvents', 'ready', setupTurboListener);
Or, if you’re already in an async function:
await wkof.ready('TurboEvents');
wkof.turbo.on.common.dashboard(main);
Take a look at one of the repositories below for more basic information, general notes, and examples.
Requirements
- WaniKani Open Framework
- While it could be rewritten to not require the WaniKani Open Framework, my goal was to add something that could be used in a way that is convenient for development. Therefore, I decided to create it in a way that works as an addon to wkof. However, that is the extent of what is needed.
- Set the
@match
userscript directive tohttps://www.wanikani.com/*
or equivalent.- Otherwise, the script may not end up running if the user refreshes the page somewhere unexpected.
Installation
As of writing, this is a library script; thus, there are limited ways of importing it.
Note that these example URLs might not always be the most up to date. Check the repositories section below for the current versions.
- The preferred method would probably be something along the lines of the following:
const scriptUrl = 'https://update.greasyfork.org/scripts/501980/1426289/Wanikani%20Open%20Framework%20Turbo%20Events.user.js';
wkof.load_script(scriptUrl, /* use_cache */ true)
- Alternatively, it can be
@required
in the script header like so:
// @require https://update.greasyfork.org/scripts/501980/1426289/Wanikani%20Open%20Framework%20Turbo%20Events.user.js
Repositories
For now, these are both manually kept in sync.
- [GitHub]
- The readme has code syntax highlighting here, which makes it much easier to read
- [Greasy Fork]
- You can get a version-locked link at the History link by clicking the desired version, copying the last part of the URL, and replacing the part after
/scripts/501980/
in the update URL with the copied version number.
- You can get a version-locked link at the History link by clicking the desired version, copying the last part of the URL, and replacing the part after
Credits
This was heavily inspired by the work of @rfindley and the discussions of @LupoMikti, @ctmf,
@Sinyaven, and others in the following thread: