6218d6bad1
update names based on the element from the mutation event rather than checking the chatbox for unchecked messages each mutation
28 lines
736 B
TypeScript
28 lines
736 B
TypeScript
import { NameConfigInstance, ignoreMod } from './options'
|
|
import { getRandomName, getStoredUser, setStoredUser } from './storage'
|
|
import { ChatMessage } from './util'
|
|
|
|
export function obfuscator(
|
|
chatMessage: ChatMessage
|
|
): NameConfigInstance | null {
|
|
if (ignoreMod && chatMessage.isMod) {
|
|
return null
|
|
}
|
|
|
|
console.log(`[OBFUSCATOR] Updating Username: ${chatMessage.username}`)
|
|
|
|
chatMessage.username = chatMessage.username.toLowerCase()
|
|
|
|
// return stored data
|
|
const userData = getStoredUser(chatMessage.username)
|
|
if (userData !== null) {
|
|
return userData
|
|
}
|
|
|
|
// store new data
|
|
const newName = getRandomName()
|
|
setStoredUser(chatMessage.username, newName)
|
|
|
|
return newName
|
|
}
|