Skip to content

Commit

Permalink
detect message added
Browse files Browse the repository at this point in the history
  • Loading branch information
PleahMaCaka committed Mar 19, 2023
1 parent 95315b6 commit 3cd4689
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/content/CharacterMessageTranslate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function initCharacterMessageTranslator() {
console.log("TavernAI Translator: Character Message Translator Enabled")
const target = document.getElementById("chat") as Element
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.type == "childList") {
const addedNodes = mutation.addedNodes
for (const node of addedNodes) {
if ((node as Element).classList.contains("mes")) {
console.log("New message added!")
const mesBlock = (node as Element).querySelector(".mes_block") as Element
mesBlock.appendChild(document.createElement("br"))
mesBlock.appendChild(document.createTextNode("Translated"))
}
}
}
})
})
observer.observe(target!!, {childList: true})
}
2 changes: 2 additions & 0 deletions src/content/content.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { initTranslator } from "./translator/AddTranslator";
import {initCharacterMessageTranslator} from "./CharacterMessageTranslate";

console.log("TavernAI Translator: content loaded")

Expand All @@ -10,4 +11,5 @@ else
window.addEventListener("load", () => {
console.log("TavernAI Translator: init translator")
initTranslator()
initCharacterMessageTranslator()
})

0 comments on commit 3cd4689

Please sign in to comment.