3 ms·
The best luck I’ve had with SPA apps and a goal of manipulating the DOM is by using mutation observers. Worth exploring if you haven’t yet https://developer.mo
by grimgrin 2y ago
The best luck I’ve had with SPA apps and a goal of manipulating the DOM is by using mutation observers. Worth exploring if you haven’t yet
https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver https://developer.mozilla.org/en-US/docs/Web/API/MutationObs...
You can hack on the behavior via userscripts, my preferred way to alter websites, though I write extensions too (greasemoney is good tho)
- rsoto 2y agoIMO MutationObserver's API is a bit difficult to grasp. For simpler cases for getting a callback when an element is created, I use spect[1] or sentinel[2]. 1: https://github.com/dy/spect https://github.com/dy/spect 2: https://github.com/kubetail-org/sentineljs https://github.com/kubetail-org/sentineljs
- sfink 2y agoYou can wimp out and just use MutationObserver as a way to get a callback whenever anything changes, ignoring all of the mutation records. Then in the callback, look up all of the elements you care about. The API is pretty simple then. It may be less efficient, but usually when you're mucking about with existing web pages, you're not all that performance sensitive. (And MO batches up updates reasonably well, so it's not like you're running the callback once per change.) Occasionally it might even be faster, since you're not iterating through the mutation records and testing for stuff you care about.
- grimgrin 2y agoyeah that's exactly how I've done it -- observe the highest order container I care about (document.body lazy mode)