Vocab sound cutting off?

I think the issue people are experiencing today might be caused by the fact that they now stop all audio playback whenever the question changes in reviews by calling Howler.unload(). The modified version of DoubleCheck here disables that feature in order to fix a problem it caused with DoubleCheck, so it might also fix the issues people in this thread are seeing. I’ve also packaged that change into its own script below if you don’t want DoubleCheck.

UserScript to Fix the Issue
// ==UserScript==
// @name        Audio Cutoff Fix
// @namespace   wkdoublecheck
// @include     /^https://(www|preview).wanikani.com/
// @version     1.0.1
// @run-at      document-end
// @grant       none
// ==/UserScript==
// don't remove audio that is currently playing or queued to play

void function() {
    function main() {
        waitProperty(window, 'Howler', function () {
            window.Howler.unload = function() {
                let howls = window.Howler._howls;
                for (let i=howls.length - 1; i >= 0; i--) {
                    if (!howls[i].playing() && howls[i]._queue.length == 0) {
                        howls[i].unload();
                    }
                }
                // might need to add something here if wk ever switches to web audio
            };
        });
    }

    // helper method for waiting for a property to be defined on an element
    // callback is called synchronously immediately after the property is defined
    if (!window.waitProperty) {
        let objPropCallbacks = new Map();
        window.waitProperty = function (obj, prop, callback) {
            if (obj[prop] !== undefined) {
                callback(obj[prop]);
                return;
            }
            if (!objPropCallbacks.has(obj))
                objPropCallbacks.set(obj, new Map());
            let propCallbacks = objPropCallbacks.get(obj);

            let callbacks;
            if (!propCallbacks.has(prop)) {
                propCallbacks.set(prop, []);

                function runCallbacks(val) {
                    for (let callback of callbacks) {
                        callback(val);
                    }
                }

                let _val;
                Object.defineProperty(obj, prop, {
                    get: () => _val,
                    set: function(val) {_val = val; delete obj[prop]; obj[prop] = val; runCallbacks(val); callbacks.length = 0;},
                    configurable: true,
                    enumerable: true
                });
            }
            callbacks = propCallbacks.get(prop);
            callbacks.push(callback);
        }
    }

    main();
}();

@WaniKaniJavi, maybe it would make sense to allow audio to continue to play after the user moves on to the next review question?

4 Likes