From d49f9be8bf48290c4856940eed43a5f0517636fe Mon Sep 17 00:00:00 2001 From: wibus-wee <1596355173@qq.com> Date: Sat, 26 Aug 2023 22:26:04 +0800 Subject: [PATCH] fix: inject addon action failed in forwarded messages window, fix #35 --- src/main.ts | 3 ++- src/utils.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index c476303..d20ed8c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,7 +3,8 @@ import { Functions } from "./functions"; import { createConsole, createConsoleGroup, getRoomsPanelWidth } from "./utils"; function init() { - if (!getRoomsPanelWidth()) { + // #app > .vac-col-messages 是用于判断是否在「转发聊天页面」页面 + if (!getRoomsPanelWidth() && !document.querySelector("#app > .vac-col-messages")) { setTimeout(init, 1000); createConsole("ADDON", "rooms-panel not found, try again after 1s"); return; diff --git a/src/utils.ts b/src/utils.ts index e221f1e..9e3fd37 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -45,8 +45,8 @@ export function getRootStyle(key: any) { } export function getRoomsPanelWidth() { - return (document.getElementsByClassName("rooms-panel")[0] as HTMLElement) - .style.width; + return (document.getElementsByClassName("rooms-panel")[0] as HTMLElement || undefined) + ?.style.width; } export function createConsole(code: string, desc: string) {