@prouleau I’ve updated the library just now to version 2.2.2 (greasyfork versionId=1423085). Sorry for the delay in pushing the changes, but there were a few other things I wanted to work out before announcing it.
The cause of the issue we were discussing in [Userscript] Show Total Lesson Count was actually quite simple. It was essentially ignoring all of the custom listeners except for the “turbo:load” one because I had logic set up to create a default listener for any events that didn’t have one already added. That wasn’t the only issue, but it sums it up well.
You also may be pleased with the new additions.
First, the callback will now be passed url
along with event
in the arguments. Second, wkof.turbo.on.common.events()
does a better job with parsing various input objects.
I bolded the first because this also means that it’s become much easier to set up your location matching in your own callback, if you would rather do it that way (though passing urls
in the options object still works to that degree).
So, something like this now works:
let callback = (event,url) => console.log(event.type,url,event);
let eventList = wkof.turbo.events;
// create a runOnce listener for every turbo event
wkof.turbo.on.common.events(eventList,callback,{once: true});
// can parse Object.entries() as well as Object.values()
let keys = ['before_cache','before_render','render','before_morph_element','frame_render','frame_load'];
let eventList = Object.entries(wkof.turbo.events).filter(([key,{name, source}])=>keys.includes(key));
wkof.turbo.on.common.events(eventList,callback,{once: true});
Another big change is that any of the properties in the turbo object that you would expect to be immutable/non-writeable are, respectively, now.