[Userscript] Detailed SRS Popup

I did a blind change that may fix this (I have no idea) while doing other changes as a result of another WK change today. I’ll eventually take an actual look at it, but I’m sure it will be next week at the earliest.

1 Like

I think that was about my version. I made a separate thread here to not confuse with two similar scripts in the same thread any further.

2 Likes

My bad. To live in such glorious times so as to have freedom of choice for userscripts that solve similar issues!

1 Like

Heads up, the update does not resolve the issue. Although it looks like you moved the didUnanswerQuestion event rather than the didAnswerQuestion event stuck_out_tongue

In set_answer_state() you have a if (!final_submit) {...} at one point and then a couple of blocks later if (final_submit) {...} else {...}. You update the SRS in the first one, and fire the didAnswerQuestion event in the second. It seems like you could just move the event into the first one (before you update SRS), but I didn’t properly test that it doesn’t affect anything else

2 Likes

Thanks for the investigative work. I’ll give that a try.

2 Likes

I’ve posted an update with this change. You may want to do additional testing, but it seems to be working as I would expect.

1 Like

Thank you!

Thank you!

Got this and discovered it isn’t working, so I tried to look into why but I’m just kind of stumped. Everything seems fine, it just that when event.detail.newLevelText is modified the change doesn’t stick. Unless I add a console.log(event.detail) immediately after that line. Then it works perfectly. And I have no idea why; I’m too much of a novice at javascript to know what makes console.log() so special that logging the event detail makes the change stick. [edit: and now it’s not working that way anymore. What is wrong with this??] Anyway, I hope this can be revived one day. I guess I’ll keep trying to fix it myself? Searching for answers isn’t yielding anything though.

Edit 2: Browser is Firefox, latest version. Found out that the detail of a custom event is supposed to be readonly, maybe this is why it’s not working?

3 Likes

I’ll put it on my list to look at

3 Likes

As another data point, it works for me in Chrome 116. So possibly browser dependant?

1 Like

It hasn’t been working for me either, also Firefox latest version (but also for previous versions, it’s been a few months since it worked for me).

Script started working again today, which means it was likely an issue with Queue Manipulator. Since Queue Manipulator was just updated to support the new lesson page changes that broke lesson reordering, and I have it installed separately so that the latest version is always used, and no other changes to the script have been made, it seems like just updating the @require in this script will now fix it.

Edit: well, it’s half working. It worked when I had Guru 1 items going to Guru 2 (and a Master item falling to Apprentice 4), but I’m doing Apprentice 2 items right now and it is not showing Apprentice 3 when it goes up.

Edit 2: now I can’t get it to work at all anymore lol. I have no idea what conditions were met to make it partially work for that single session of reviews I did

Edit 3: and just like that, by making inconsequential changes it worked perfectly this time around. All I did though was add two console.log statements around the wkQueue line (because I needed to test something related to Queue Manipulator and order of execution with async functions) and have the browser console open during reviews. I mention having the console open because I thought this was the important factor that made it work, because it stopped working for my next review session. But I had it open for the one after that and it wasn’t working then either. So it seems like it only works the first time after making a change to the code.

2 Likes

Unfortunately still doesn’t work for me either in Firefox (desktop and mobile). Script works in Chrome, so it’s definitely browser dependent. I’m on the latest versions of all scripts/browsers.

2 Likes

So I still have no idea why sometimes it would work after an arbitrary change in the code but then never again, but I fixed this script.

The problem is indeed that Chrome treats the detail and detail properties as mutable by default whereas they are immutable in Firefox (which means those times where it randomly worked for me mean there is some kind of obscure bug in Firefox where you can mutate the immutable). The solution so that it works in all browsers is to simply dispatch a new didChangeSRS event with the new detail. I change the inside of the change_srs_name function to this:

if (!last_item) return
const new_srs = calculate_resulting_srs(last_item)

const modified_event = new CustomEvent('didChangeSRS', {
    detail: {
        wentUp: event.detail.wentUp,
        newLevelText: srs_stages[new_srs]
    }
})

event.preventDefault()
window.dispatchEvent(modified_event)

And it’s all good now.

2 Likes

Updated the script with your fix

2 Likes

Awesome. I just noticed while attempting to update and overwrite my local changes that the Queue Manipulator version is old (I have it installed separately so old versions never affect me. I’m not sure whether this old version is broken for reviews or not though, so it may unintentionally be fine).

2 Likes

Ah, thanks for the heads up

1 Like

Now it seems to be broken in Chrome, as since installing the new version, I’m no longer getting the detailed messages.

By the time I realized, and checked the console, I only had reviews that went to Guru left, but I got this error in the console each time I completed one of those items:

userscript.html?name=Wanikani%253A-Detailed-SRS-Popups.user.js&id=47250d6f-0e77-43c8-8475-6f22eabd7d33:684 Uncaught RangeError: Maximum call stack size exceeded.
at change_srs_name (userscript.html?name=Wanikani%253A-Detailed-SRS-Popups.user.js&id=47250d6f-0e77-43c8-8475-6f22eabd7d33:684:16)
at nrWrapper (review:7:16282)
at change_srs_name (userscript.html?name=Wanikani%253A-Detailed-SRS-Popups.user.js&id=47250d6f-0e77-43c8-8475-6f22eabd7d33:684:16)
at nrWrapper (review:7:16282)
at change_srs_name (userscript.html?name=Wanikani%253A-Detailed-SRS-Popups.user.js&id=47250d6f-0e77-43c8-8475-6f22eabd7d33:684:16)
at nrWrapper (review:7:16282)
at change_srs_name (userscript.html?name=Wanikani%253A-Detailed-SRS-Popups.user.js&id=47250d6f-0e77-43c8-8475-6f22eabd7d33:684:16)
at nrWrapper (review:7:16282)
at change_srs_name (userscript.html?name=Wanikani%253A-Detailed-SRS-Popups.user.js&id=47250d6f-0e77-43c8-8475-6f22eabd7d33:684:16)
at nrWrapper (review:7:16282)

1 Like

Why must Chrome make this so complicated by not following the standard… Apologies that it broke for you, I myself do not have Chrome so neglected to actually test it there. All of the resources I could find suggested that this should simply work as a cross-browser solution, and I am unsure why the recursion does not happen in Firefox.

Try this and see if it solves the issue:

Add , didDispatchModifiedEvent = false next to let last_item and replace the if-statement in change_srs_name with

if (!last_item || didDispatchModifiedEvent) return
didDispatchModifiedEvent = true

Then add the following under the other window.addEventListener lines:

window.addEventListener('willShowNextQuestion', (event) => {
    if (didDispatchModifiedEvent) didDispatchModifiedEvent = false
})

Edit 3: If you need this to work with Double-Check, you should actually extract that anonymous function in the above event listener into its own named function and also add an event listener for “didUnanswerQuestion” that calls that function (and change “willShowNextQuestion” to call this function too). Then also call this new function as the first line in update_stats. So it should look like this instead:

window.addEventListener('willShowNextQuestion', resetDispatchFlag)
window.addEventListener('didUnanswerQuestion', resetDispatchFlag)

function resetDispatchFlag(event) {
    if (didDispatchModifiedEvent) didDispatchModifiedEvent = false
}

...

// Keep track of the stats of the most recent item
let last_item, didDispatchModifiedEvent = false
function update_stats(event) {
    resetDispatchFlag()
    const id = event.detail.subjectWithStats.subject.id
    item_data[id].stats = event.detail.subjectWithStats.stats

    last_item = item_data[id]
}
1 Like