diff --git a/src/styles.css b/src/styles.css
index 6f6d304b..71442e6f 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -175,4 +175,8 @@ html, body{
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
+}
+
+.x-risu-button-default{
+ @apply border text-textcolor rounded-md shadow-sm focus:outline-none focus:ring-2 transition-colors duration-200 border-darkborderc px-4 py-2 bg-darkbutton hover:bg-borderc focus:ring-borderc
}
\ No newline at end of file
diff --git a/src/ts/observer.ts b/src/ts/observer.ts
index ab61c536..c2184de7 100644
--- a/src/ts/observer.ts
+++ b/src/ts/observer.ts
@@ -4,43 +4,59 @@ import { CurrentCharacter, CurrentChat } from "./stores";
import { runCharacterJS } from "./plugins/embedscript";
+function nodeObserve(node:HTMLElement){
+ const triggerName = node.getAttribute('risu-trigger');
+ const btnEvent = node.getAttribute('risu-btn');
+ const observerAdded = node.getAttribute('risu-observer');
+
+ if(observerAdded){
+ return
+ }
+ if(triggerName){
+ node.addEventListener('click', async () => {
+ const currentChar = get(CurrentCharacter)
+ if(currentChar.type === 'group'){
+ return;
+ }
+ const triggerResult = await runTrigger(currentChar, 'manual', {
+ chat: get(CurrentChat),
+ manualName: triggerName,
+ });
+
+ if(triggerResult){
+ CurrentChat.set(triggerResult.chat);
+ }
+
+ }, {
+ passive: true,
+ });
+ node.setAttribute('risu-observer', 'true');
+ return
+ }
+
+ if(btnEvent){
+ node.addEventListener('click',async ()=>{
+ await runCharacterJS({
+ code: null,
+ mode: 'onButtonClick',
+ data: btnEvent
+ })
+ }, {passive: true})
+ node.setAttribute('risu-observer', 'true');
+ return
+ }
+}
+
export function startObserveDom(){
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
const node = mutation.target as HTMLElement;
- const triggerName = node.getAttribute('risu-trigger');
- const btnEvent = node.getAttribute('risu-btn');
-
- if(triggerName){
- node.addEventListener('click', async () => {
- const currentChar = get(CurrentCharacter)
- if(currentChar.type === 'group'){
- return;
- }
- const triggerResult = await runTrigger(currentChar, 'manual', {
- chat: get(CurrentChat),
- manualName: triggerName,
- });
-
- if(triggerResult){
- CurrentChat.set(triggerResult.chat);
- }
-
- }, {
- passive: true,
- });
+ if(node.nodeType !== 1){
+ return;
}
-
- if(btnEvent){
- node.addEventListener('click',async ()=>{
- await runCharacterJS({
- code: null,
- mode: 'onButtonClick',
- data: btnEvent
- })
- }, {passive: true})
- }
-
+ node.querySelectorAll('[risu-trigger]').forEach(nodeObserve);
+ node.querySelectorAll('[risu-btn]').forEach(nodeObserve);
+ nodeObserve(node)
});
});
@@ -48,5 +64,6 @@ export function startObserveDom(){
childList: true,
subtree: true,
attributeFilter: ['risu-trigger', 'risu-btn'],
+ attributes: true,
});
}
\ No newline at end of file
diff --git a/src/ts/parser.ts b/src/ts/parser.ts
index e5943a3a..27b7c1ed 100644
--- a/src/ts/parser.ts
+++ b/src/ts/parser.ts
@@ -732,7 +732,7 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
return null
}
case 'button':{
- return ``
+ return ``
}
case 'risu':{
return `
`
diff --git a/src/ts/storage/globalApi.ts b/src/ts/storage/globalApi.ts
index ef1001aa..24b19186 100644
--- a/src/ts/storage/globalApi.ts
+++ b/src/ts/storage/globalApi.ts
@@ -30,6 +30,7 @@ import type { RisuModule } from "../process/modules";
import { listen } from '@tauri-apps/api/event'
import { registerPlugin } from '@capacitor/core';
import { language } from "src/lang";
+import { startObserveDom } from "../observer";
//@ts-ignore
export const isTauri = !!window.__TAURI__
@@ -508,6 +509,7 @@ export async function loadData() {
}
loadedStore.set(true)
selectedCharID.set(-1)
+ startObserveDom()
saveDb()
} catch (error) {
alertError(`${error}`)