[Userscript] Detailed SRS Popup

I’m not sure if this solution is working for me. I also have Double-Check installed and tried following your instructions. Would you be willing to post a full version of this fix that I could just copy-paste to make sure?

Starting from under the event listener for ‘didChangeSRS’ and ending just before the last function:

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

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

// Get latest item SRS info
function update_item_srs(queue) {
    for (let item of queue) {
        item_data[item.id] = { srs: item.srs, stats: {} }
    }
}

// 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]
}

// Change the name in the popup
function change_srs_name(event) {
    if (!last_item || didDispatchModifiedEvent) return
    didDispatchModifiedEvent = true
    const new_srs = calculate_resulting_srs(last_item)

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

    window.dispatchEvent(modifiedEvent)
}

So, apparently something changed today, and my fix stopped working. The culprit was the event.preventDefault(). Removing it makes it work again. (I suspect the original event was changed to have cancelable set to false, but as I never checked before my fix what the value of that was I can’t say for sure).

1 Like

Pushed a fix that doesn’t recurse infinitely

Awesome. I’m still not sure why the recursion never happened in Firefox. Browsers are weird.

1 Like

Ok, finally had Apprentice and Guru reviews today. Sadly it wasn’t working for me, for the same reason as above with preventDefault, this time with stopImmediatePropogation. For some reason, having either of those just makes it not work. If I comment the line out, it works. If this isn’t happening in Chrome, then truly I do not understand the differences in implementation between these browsers.

1 Like

I tried it in Firefox myself and it worked just fine. What exactly makes it not work?

Well, actually you can see my issue from my comment. Spelled propagation wrong. 's what I get for being too lazy to retype my 3 small edits once Tampermonkey overwrites the script (I change the matches to only run on the reviews and add the /* global wkQueue */ comment that Tampermonkey wants so it stops putting a warning about it). Apologies for making you take up any time on that.

I don’t understand why either preventDefault or stopImmediatePropagation would cause any issues, in any browser.

Oh, sorry I wasn’t clear. I spelled Propagation wrong when typing it in myself, so that’s why it wasn’t working. It works fine now. However, preventDefault still causes it to not work for me. The weird thing is that it was working fine with preventDefault then just stopped working in the very same day (I did reviews that morning, all was good. I did reviews that evening, suddenly not working and removing preventDefault fixed it). I assumed it was because the event’s cancelable property was set to false, but I don’t know if it was always false or if it was changed to false. Who knows, maybe if I change it back to preventDefault some days from now it’ll magically work again.

1 Like

Ah, okay, thank you for clarifying. I think according to spec calling preventDefault on a non cancelable event should just have no effect, so that is very strange.

Just popping in to say this isn’t currently working for me. I use Firefox and doublecheck. Not getting errors, but it isn’t doing anything either.

Check your Double-Check version. It should be 3.1.13.

Please confirm that you have Double Check v3.1.13 and Detailed SRS Popups v.1.0.4 and let me know if it’s not working with those versions installed. FWIW it’s working fine for me with those versions on Firefox

Also can you confirm that you are still seeing popups at all?

Not quite sure what was going on. I had been seeing no popups at all, did a full system restart and still the same issue, which is why I posted.

Just now noticed today, though, that it’s working. Didn’t change anything, on the same computer/browser as before.

Guess I won’t question it as long as it keeps working.

1 Like

I don’t suppose it’s possible you toggled the WK setting for it? WK has a setting to not show those popups

This isn’t working for me. I tried turning off all other scripts (except Open Framework), but it still doesn’t work. Also, when this script is turned on, when I click the review button on the dashboard, the blue loading bar at the top very slowly fills up but never actually loads. I have to reload the review url to get to the review screen.

Install WK Queue Manipulator and put it before this script in the load order.

This script depends on that library via @require, but it hasn’t updated the referenced version in a while, and it seems that something is causing older versions to not function properly. Installing the library locally will force it to use the newer version.

I installed and set it to run before all the other scripts except for Open Framework, but now every time I review an item, it just says “You have lost connection with Wanikani”