this post was submitted on 19 Aug 2023
4 points (75.0% liked)
FF addons&extensions
278 readers
1 users here now
Share your Firefox extensions or search tools.
founded 3 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
You'll likely want to take a look at MutationObservers. That's the most modern way that I know of to handle SPAs like Lemmy. (Well, Lemmy is technically a hybrid in that the first load is done server-side, which is why your addon works when you refresh)
I tried it a bit, but now it repeatedly activates the extension and lags the browser.
You may want to give a go at my implementation of MutationObserver for lemmy-keyboard-navigation --> https://github.com/vmavromatis/Lemmy-keyboard-navigation/blob/main/lemmy-keyboard-navigation.user.js#L636-L652 I did have to use
onload
for the initial page load though :/End result -> https://addons.mozilla.org/en-US/firefox/addon/lemmy-keyboard-navigation/
I ended up going primitive and used intervals to check if a particular div was visible:
function refreshExtension() { console.log("checking ", shown); const targetNode = document.getElementsByClassName("person-details")[0]; if (!shown && targetNode) { main(); } if (!targetNode) { shown = false; } } setInterval(refreshExtension, 200);
will it affect performance?