[For Userscript Authors] WK Queue Manipulator

Version 1.5:

Now also affects the recent mistakes extra study mode

Actions registered for wkQueue.on("extraStudy") will now also affect the recent mistakes quiz and the recent mistakes lesson quiz. For now, I decided that Queue Manipulator will not affect the recent mistakes lessons. If there is demand for it, I might reconsider.

// @require      https://greasyfork.org/scripts/462049-wanikani-queue-manipulator/code/WaniKani%20Queue%20Manipulator.user.js?version=1251359

I will try to look into adapting this to the WaniKani lesson changes after I come home from work, but it seems that this requires a bigger change, so the fix might take a few days.

Version 1.6:

Updated to work with the recent lesson changes

The recent update to the lessons page removed the possibility to pass a custom lesson batch through an URL parameter. The workaround modifies the links in the page to replace the queue received from WaniKani with the custom queue.

I just finished writing the code and did not have time for sufficient testing, but I have to go to bed. Due to the seemingly high demand for the lesson fix, I decided to release the untested version. Please let me know of any problems you encounter.

// @require      https://greasyfork.org/scripts/462049-wanikani-queue-manipulator/code/WaniKani%20Queue%20Manipulator.user.js?version=1276688

Ahh, I wish I had lessons to test with right now. You’re amazing for getting this done at all, I was at a loss for how to approach fixing this. Thank you so much! I’ll take a look at what you’ve done later and (if I later see it works) see if I can apply that to the way Lesson Filter script works so that one can be fixed too.

Version 1.7:

  • Bugfix for continuing lessons after a lesson quiz (completed items have to be removed from the queue)
// @require      https://greasyfork.org/scripts/462049-wanikani-queue-manipulator/code/WaniKani%20Queue%20Manipulator.user.js?version=1277127

Version 1.8:

  • Fixed a really dumb bug (I left my own queue id in the code, so the links at the bottom of the lesson page were only working for me and nobody else) :person_facepalming:
// @require      https://greasyfork.org/scripts/462049-wanikani-queue-manipulator/code/WaniKani%20Queue%20Manipulator.user.js?version=1277610

I believe queue manipulator does some handling of the classes of the character header, right? I’m seeing a bug where my radicals (during the lesson quiz, not the regular lesson part) are colored as vocabulary because the div with class character-header and attribute data-controller="quiz-header" is getting both the character-header--vocabulary and character-header--radical classes.

Sadly I don’t have any more radicals to test with after writing this message, sorry.

Something must have just changed with the html of the list of items at the bottom of the lesson because their styling gets all messed up by queue manipulator remaking them. The new line for li.innerHTML should be this:

li.innerHTML = `<a class="subject-character subject-character--${b.item.object.replace(`kana_vocabulary`, `vocabulary`)} subject-character--tiny subject-character--unlocked" title="${b.item.data.readings?.[0].reading ?? b.item.data.slug}" href="${url.replace(/\/\d+$/, `/${b.id}`)}" data-turbo-frame="_blank"><div class="subject-character__content"><span class="subject-character__characters" lang="ja">${b.item.data.characters ?? b.item.data.slug}</span></div></a>`;

Thanks for reporting.


Version 1.9:

  • Updated HTML for the lesson queue at the bottom of the lesson page
// @require      https://greasyfork.org/scripts/462049-wanikani-queue-manipulator/code/WaniKani%20Queue%20Manipulator.user.js?version=1279923

Discovered a slight bug. Probably overlooked because no one really hovers over the little item tiles at the bottom of a lesson to read their title attributes. Anyway, the issue is that the code just gets the first reading from the api but this is not always the primary reading taught. In modifyLessonPageBatch, b.item.data.readings?.[0].reading needs to be changed to b.item.data.readings?.find(r => r.primary).reading.

Version 1.10:

  • Updated to hopefully work with the WK lesson picker update

I don’t have time for extensive testing, and the fix is not exactly optimal, but I think it should work…? Also includes the bugfix reported by @LupoMikti in the previous post.

https://greasyfork.org/scripts/462049-wanikani-queue-manipulator/code/WaniKani%20Queue%20Manipulator.user.js?version=1325980

Version 1.11:

  • Bugfix for endless loop when starting lessons from lesson picker with registered manipulations
// @require      https://greasyfork.org/scripts/462049-wanikani-queue-manipulator/code/WaniKani%20Queue%20Manipulator.user.js?version=1326122

Now that I’m thinking a bit more about it, in the case of lessons started from the lesson picker, Queue Manipulator should probably take the user selected items as the base queue. Currently, it completely disregards the user choice and starts with the queue of all unlearned items, leading to the same behavior as with clicking “Start Lessons” on the dashboard.

Version 1.12:

  • When starting lessons from the lesson picker, use the items selected by the user as the base queue
// @require      https://greasyfork.org/scripts/462049-wanikani-queue-manipulator/code/WaniKani%20Queue%20Manipulator.user.js?version=1326150

Oh, awesome, thanks for fixing that.

When looking at the diff before updating I noticed something else I had fixed but apparently completely forgot to post about here. Using the slug for radical images means the item tile at the bottom will use the text instead of the radical image, making it look broken. So we can instead make use of the component.

Instead of:

<span class="subject-character__characters" lang="ja">${b.item.data.characters ?? b.item.data.slug}</span>

Use something like:

`
<span class="subject-character__characters" lang="ja">
    ${b.item.data.characters ??
        `<wk-character-image class="subject-character__character-image"
            src="${b.item.data.character_images.filter(img => img.content_type === 'image/svg+xml' && img.metadata.inline_styles)[0]?.url ?? ''}"
            aria-label="${b.item.data.slug}">
        </wk-character-image>`
    }
</span>
`

But like, probably all on one line like you have it, and maybe some handling for if the src url comes back undefined other than empty string.

Edit: also, since the setting for lesson order has been removed, you might want to look into what the fetchLessonSettings function is returning and modify things to no longer take into account lesson order.

With version 1326150 I am seeing an endless loop after clicking “Start Lessons” from the dashboard, with an empty post processing step registered

window.wkQueue.addPostprocessing(() => {})

Sorry for the late reply! This endless loop should be fixed now.

Thank you for providing the code! I have included it in the new release.


Version 1.13:

  • Bugfix for endless loop on lesson start with @Kumirei’s Random Voice Actor script
  • Added support for image radicals in lessons (code provided by @LupoMikti)
// @require      https://greasyfork.org/scripts/462049-wanikani-queue-manipulator/code/WaniKani%20Queue%20Manipulator.user.js?version=1340063

Thank you!

Thank you for your work and time in maintaining this and looking over my suggestions!

There’s something I’ve been wondering about for a while, but why is the line that assigns the html to the list item duplicated (inside modifyLessonPageBatch just before return li;)? Before, it used to be the line was fully duplicated with no difference between the two. I think at some point I suggested the change in structure but only one of the lines got the new structure and the other didn’t; it was the second line so it was reassigning the correct structure. With this update, now the first line has incorrect structure + component fix and the second line has correct structure but no fix for the component, meaning the final assignment does not contain the component fix and we would still see the slug name instead.

Unless there’s a reason for the duplication I’m not seeing, the full line should be

li.innerHTML = `<a class="subject-character subject-character--${b.item.object.replace(`kana_vocabulary`, `vocabulary`)} subject-character--tiny subject-character--unlocked" title="${b.item.data.readings?.find(r => r.primary).reading ?? b.item.data.slug}" href="${url.replace(/\/\d+$/, `/${b.id}`)}" data-turbo-frame="_blank"><div class="subject-character__content"><span class="subject-character__characters" lang="ja">${b.item.data.characters ??`<wk-character-image class="subject-character__character-image" src="${b.item.data.character_images.filter(img => img.content_type === 'image/svg+xml' && img.metadata.inline_styles)[0]?.url ?? ``}" aria-label="${b.item.data.slug}"></wk-character-image>`}</span></div></a>`;

and there should only be one of them.

Have been getting the following since the latest update after clicking “Continue with new lessons” and it just stays on this screen. (Using reorder omega and back to back)

edit: Seems to be originating from back to back @Kumirei for vis

Sorry, I had completely forgotten about this – thank you for pointing out my careless mistakes. :sweat_smile: This fix is now included in the new version.


Version 1.14:

  • Bugfix for links at bottom of lesson pages
  • Bugfix for handling svg element remaining in new body after Turbo load
// @require      https://greasyfork.org/scripts/462049-wanikani-queue-manipulator/code/WaniKani%20Queue%20Manipulator.user.js?version=1386112