From 115999652a27d7daa4725271ffb4083e7589dda1 Mon Sep 17 00:00:00 2001 From: Hakadao Date: Thu, 3 Oct 2024 02:32:46 +0800 Subject: [PATCH] fix(settings): cannot change the bewly's shadow dom style immediately --- .../views/necessarySettingsWatchers.ts | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/contentScripts/views/necessarySettingsWatchers.ts b/src/contentScripts/views/necessarySettingsWatchers.ts index 8fe78357..ac1ee058 100644 --- a/src/contentScripts/views/necessarySettingsWatchers.ts +++ b/src/contentScripts/views/necessarySettingsWatchers.ts @@ -166,18 +166,22 @@ export function setupNecessarySettingsWatchers() { const bewlyEl: HTMLElement | null = document.querySelector('#bewly') const bewlyShadow: ShadowRoot | null = bewlyEl?.shadowRoot || null + document.querySelectorAll('[data-bewly-customizeCSS]').forEach((el) => { + el.remove() + }) + + bewlyShadow?.querySelectorAll('[data-bewly-customizeCSS]').forEach((el) => { + el.remove() + }) + if (settings.value.customizeCSS) { styleEL = injectCSS(settings.value.customizeCSSContent) + styleEL.setAttribute('data-bewly-customizeCSS', '') - if (bewlyShadow) + if (bewlyShadow) { bewlyStyleEL = injectCSS(settings.value.customizeCSSContent, bewlyShadow) - } - else { - if (styleEL) - document.documentElement.removeChild(styleEL) - - if (bewlyShadow && bewlyStyleEL) - bewlyShadow.removeChild(bewlyStyleEL) + bewlyStyleEL.setAttribute('data-bewly-customizeCSS', '') + } } }, { immediate: true },