Okay, thanks. The fix is in 1.2.3
@rfindley
Can I request a feature related to on_pageload
?
I would like for scripts to have a simple way to handle the user exiting the desired page.
In particular, this is useful for any listeners added or modifications made to window
or document.body
. Think of it like a finally
block, where script cleanup can occur.
You may want to read my recent post(s) in the Jitai thread if you want a better idea of where I’m coming from.
Theoretically, this could be quite elegant, such that the firing of the on_pageload
callback acts as an on
switch for this second callback, which is then fired once and switched back off
when the page navigates somewhere that fails the regex for the earlier callback, and/or perhaps it just checks if the previous URL matched the regex (and the upcoming URL does not). Though a more basic example could just have it act as a negative version of on_pageload
’s regex test. The latter would result in more calls, which could technically have performance side effects and is a bit undesirable from a conceptual standpoint, but it also is probably much easier to create, and something is better than nothing, so that’s why I am proposing both.
I had put a lot of thought into that while making the on_pageload
, and ultimately decided to wait until someone requested it. That way, I could get a fix out the door faster, and I wouldn’t spend time on something until I knew people actually wanted it.
Now that it has been requested, I will revisit what I was thinking. I currently have some optimizations that aren’t compatible with doing ‘exit’ calls, but it’s not a problem to change it.
New version of Open Framework (v1.2.4):
- Added try-catch blocks around pageload callbacks to stop errors in one script from affecting other scripts.
- Added support for
unload_handler
parameter towkof.on_pageload
:
Example1:
wkof.on_pageload(
[ // The dashboard has two possible URLs
'/',
'/dashboard'
],
load_ultimate_timeline,
unload_ultimate_timeline //(optional)
);
Suppose you start on /dashboard. wkof will call:
load_ultimate_timeline("/dashboard", 1);
// The "1" means that the second URL pattern was matched.
Then if you click on the WaniKani logo in the upper left, which navigates to “/”, wkof will call:
load_ultimate_timeline("/", 0);
// Again, the "0" means that the first URL pattern was matched.
If you then click on the Reviews button, wkof will call:
unload_ultimate_timeline("/", 0);
The on_pageload
function broke for me. It looks like there is a typo on line 366 wich should be regex = regex_entry.regex;
I think, instead of regex = cache_entry.regex;
Fixed! Thanks for the heads-up. Looks like I had a hole in my test cases.