Spyke
firefox_addons·FF addons&extensionsbyYoru

I need help with my extension

so I was making an extension for firefox where it calculates and displays a user's Karma. Now the extension works perfectly fine when you paste in your profile and go there, or if you refresh your profile. but if you go to the main menu of Lemmy, then back to your profile by clicking on your profile, the extension simply doesn't work.

I need help with my extensionhttps://github.com/YoruNoKen/LemmyKarmaCalculatorExtensionOpen linkView original on lemmy.ml

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)

2
Yorureply
lemmy.ml

I tried it a bit, but now it repeatedly activates the extension and lags the browser.

1

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?

1

You reached the end

I need help with my extension | Spyke