changed observer callback
update names based on the element from the mutation event rather than checking the chatbox for unchecked messages each mutation
This commit is contained in:
@@ -1,37 +1,17 @@
|
||||
import { loadAdditionalUserNames, loadChatMessage } from './dom'
|
||||
|
||||
const OBSERVER_RATE_LIMIT = 1
|
||||
let observerLastRun: number = 0
|
||||
|
||||
function observerCallback() {
|
||||
if (Date.now() - observerLastRun < OBSERVER_RATE_LIMIT) {
|
||||
return
|
||||
}
|
||||
observerLastRun = Date.now()
|
||||
|
||||
const chatbox = document.querySelector<HTMLDivElement>(
|
||||
'.chat-scrollable-area__message-container'
|
||||
)
|
||||
const chatboxMessages = Array.from(chatbox?.children ?? [])
|
||||
|
||||
for (const chatboxMessage of chatboxMessages) {
|
||||
// set flag on message
|
||||
if (chatboxMessage.classList.contains('obf-loaded')) {
|
||||
continue
|
||||
}
|
||||
|
||||
loadChatMessage(chatboxMessage)
|
||||
loadAdditionalUserNames(chatboxMessage)
|
||||
}
|
||||
}
|
||||
import { eachMutation } from './dom'
|
||||
|
||||
// attach observer
|
||||
const observer = new MutationObserver(observerCallback)
|
||||
const observer = new MutationObserver((mutationRecords: MutationRecord[]) => {
|
||||
for (const record of mutationRecords) {
|
||||
eachMutation(record)
|
||||
}
|
||||
})
|
||||
observer.observe(document, { attributes: true, childList: true, subtree: true })
|
||||
|
||||
// attach styles
|
||||
const styleAddition = document.createElement('style')
|
||||
styleAddition.innerHTML = `
|
||||
/* hide badges, except broadcaster and moderator */
|
||||
.chat-line__message--badges {
|
||||
display: none;
|
||||
}
|
||||
@@ -46,10 +26,17 @@ styleAddition.innerHTML = `
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/* disable 7tv paint colors */
|
||||
.seventv-paint {
|
||||
background-image: none !important;
|
||||
}
|
||||
|
||||
/* disable username translations */
|
||||
.chat-author__intl-login {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* style image when used as name */
|
||||
img.obf-image {
|
||||
vertical-align: middle;
|
||||
margin: -0.5rem 0;
|
||||
|
||||
Reference in New Issue
Block a user