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.
Hello all. This is a script that was made in response to a request made in the Script Request thread several months ago. With the recent updates to the site, I had to update this script and it has a reached a point where it makes more sense to give it its own thread than to keep it secluded to that request thread.
Without further ado…
What does this script do?
This script replaces the daily lesson count shown on the lesson tile on the dashboard and in the lesson start navigation item in the top bar with the total number of available lessons. It has an option where you can choose to display only the total lesson count or both the daily amount and the total amount together on the lesson tile (not in the navigation bar though, that will either be the total or the daily). The numbers should update as you do lessons.
Links
You can grab the script from Greasyfork here.
I don’t currently have it hosted on my github but I will in the future and update here.
Original post
Continued changelog
v0.5.9 - 0.5.10 - Fixes typos in variables and tries to improve handling of turbo events/navigation
v0.5.8 - Update TurboEvents library dependency
v0.5.7 - Fix error for non-local instances of the TurboEvents library
v0.5.2 - 0.5.6 - Various fixes for global state management. Add a way for the script to run at least once if the turbo events are not firing properly. Fix an issue with the hiding of the start button on the lesson tile. More logging improvements.
v0.5.1 - Fix saving of settings
v0.5.0 - More logging improvements, navigation execution improvements, deprecation of the preferred daily amount settings
v0.4.11 - Changes that finally address intermittent loading issues
v0.4.10 - Dependency update + minor improvements
v0.4.9 - Update TurboEvents library dependency.
v0.4.8 - Update library dependency to hopefully fix an issue with intermittent failure to register the turbo event listeners. Also further improves the debug logging.
v0.4.7 - More improvements for logging
v0.4.6 - Improvements to the debug logging (accounting for when script fails to reach main())
v0.4.5 - Added debugging setting and debug logging. On by default as it outputs with console.debug() not console.log()
v0.4.4 - Update hover tip text in settings and update support url
v0.4.3 - Update maximum preferred daily amount to match Wanikani’s
v0.4.2 - Explicitly await load_script
v0.4.1 - Fix dependency url
This matches the behavior I was seeing until I fixed all scripts I have for turbo. Currently I no longer get the failure to modify the turbo frames because of this. Since I won’t be able to easily reproduce the intermittent behavior, I’ll try to get an update pushed that makes turning on the console debugging as simple as turning on a setting for it.
I turned off all my script except Open Framework and Airagoshi’s which is turbo enabled. I still have the problem except that it is more likely to display the Total Lesson Count. In other words it is still intermittent but with a greater probability that it works than what it was with all my scripts turned on.
When I turned off Airagoshi’s script then the problem doesn’t occur at all.
This has the smell of a race condition, possibly caused by a mishandled promise somewhere. When doing a refresh all scripts fire at once which cause a greater load on the browser and has a greater probability to trigger the bug. When navigating with turbo fewer scripts fire and their workload is lighter. The bug has less room to manifest.
Thanks, I’ll do some testing related to this finding and see if I can come up with something that more or less guarantees internal consistency without being affected by other scripts and events.
@Inserio@LupoMikti I think I know what is the bug. It is an issue I ran into when developing Item Inspector. I am sorry for not connecting the dots sooner.
wkof.load_script returns a promise that resolves when the script is done loading, not when the loaded script is done initializing. This means the Show Total Count script does not properly synchronize with the Turbo Event Library because there is a race condition involving the initalization of the library.
The solution is the turbo event library callsj wkof.set_state(someScriptId, 'Ready') when it is done initializing and the Show Total Lesson script calls wkof.wait_state(someScriptId, 'Ready') after doing wkof.load_script. This returns a promise that resolves when the turbo event library makes a corresponding call to wkof.set_state
Though I believe the wkof.ready(someScriptId) is essentially just a convenience function for wkof.wait_state(someScriptId, 'Ready'). The latter allows additional functionality, but most usages of the former are essentially just a shortcut.
Yes this is what is needed. It is not mentioned in the script documentation so I erroneously assumed you didn’t have it, I now see that what is missing is only the documentation so people know they need a corresponding wkof.wait_state
I had to go check for myself that I didn’t include it because I had an inkling that I had at least included it an example or something. But you’re right. To be fair, I was also right, it’s just that I had only included it in the examples for the description at the GitHub/Greasy Fork links.
I see that Show Total Lesson Count has a wkof.ready('TurboEvents') call. According to my tests this does the job. So I was wrong. The issue is not what I thought iis.t`
The i disabled my scripts to get the intermittent behavior. The idea was to see the difference between the path when the script is working and when it is not working.
What’s additionally concerning to me is how in your ‘working’ example, turbo:before-frame-render also seemed to never fire, which shouldn’t be the case as you successfully got turbo:frame-load. This will be difficult to reproduce because for me the events are never missing, even when I was observing intermittent behavior myself. Thank you for the continued help in investigating.
My only thought is that the wrong element is being listened to. I notice that in the library it uses document.documentElement.addEventListener but in other scripts I’ve modified I use window.addEventListener. I am wondering if I changed the script from using the library (which I like due to the simplification of URL checking) whether the issue would go away due to using window.addEventListener.