crowbartools / MixrElixr

Browser extension that enhances your Mixer viewing experience with custom emotes, new features, and a ton of options.
https://mixrelixr.com
GNU General Public License v3.0
23 stars 7 forks source link

Use MutationObserver instead of spamming elementExists check #67

Closed LeaPhant closed 5 years ago

LeaPhant commented 5 years ago

So I noticed sometimes the addon doesn't load correctly cause the chat takes too long to load for me. Instead of doing a loop that checks for the element you could use an Observer on the document that catches any new elements loading.

Relevant lines in code: https://github.com/crowbartools/MixrElixr/blob/010f60417a13456f5b96e24cb7c8f01a51180ab8/src/injected-content/mixrelixr.js#L55-L84

Error I'm experiencing: image

ebiggz commented 5 years ago

Great suggestion.

We already use MutationObserver for detecting new chat messages being created via the jquery.initialize plugin (just a wrapper for MO). So we'll just need to refactor our waitForElementAvailablity function to use that instead of looped timeouts.

Appreciate the input, not sure why we haven't made the switch to MOs all this time.

ebiggz commented 5 years ago

This has been implemented in v2.3.0