diff --git a/src/contentScripts/index.ts b/src/contentScripts/index.ts index a24037d3..8ebacd85 100644 --- a/src/contentScripts/index.ts +++ b/src/contentScripts/index.ts @@ -198,6 +198,8 @@ function injectApp() { }, 500) } + startShadowDOMStyleInjection() + // inject svg icons const svgDiv = document.createElement('div') svgDiv.innerHTML = SVG_ICONS @@ -209,3 +211,35 @@ function injectApp() { setupApp(app) app.mount(root) } + +function injectStyleToShadowDOM(shadowRoot: ShadowRoot) { + if (!shadowRoot.querySelector('style[data-bewly-style]')) { + const styleEl = document.createElement('style') + styleEl.setAttribute('data-bewly-style', 'true') + // Reset the theme color to ensure the theme color is updated + styleEl.textContent = ` + @import url(${browser.runtime.getURL('dist/contentScripts/style.css')}); + * {--bew-theme-color: ${settings.value.themeColor};}` + shadowRoot.appendChild(styleEl) + } +} + +function injectStylesRecursively(root: Document | ShadowRoot) { + if (root instanceof ShadowRoot) { + injectStyleToShadowDOM(root) + } + + root.querySelectorAll('*').forEach((element) => { + if (element.shadowRoot) { + injectStylesRecursively(element.shadowRoot) + } + }) +} + +function startShadowDOMStyleInjection() { + if (isSupportedPages()) { + setInterval(() => { + injectStylesRecursively(document) + }, 1000) + } +} diff --git a/src/styles/adaptedStyles/index.ts b/src/styles/adaptedStyles/index.ts index f31c5bbc..7a48b0a4 100644 --- a/src/styles/adaptedStyles/index.ts +++ b/src/styles/adaptedStyles/index.ts @@ -7,6 +7,7 @@ import './common/btn.scss' import './common/userCard.scss' import './common/videoPlayer.scss' import './common/loginDialog.scss' +import './shadowDom/comments.scss' import { isHomePage } from '~/utils/main' diff --git a/src/styles/adaptedStyles/shadowDom/comments.scss b/src/styles/adaptedStyles/shadowDom/comments.scss new file mode 100644 index 00000000..b5c07060 --- /dev/null +++ b/src/styles/adaptedStyles/shadowDom/comments.scss @@ -0,0 +1,22 @@ +:host(bili-comment-user-info) { + #user-name a[style*="color"] { + color: var(--bew-theme-color) !important; + } +} + +:host(bili-comment-renderer) { + #body.dark .tag[style] { + --bili-comment-tag-color: var(--bew-text-2); + --bili-comment-tag-bg: var(--bew-fill-1); + } +} + +:host(bili-rich-text) { + --bili-rich-text-link-color: var(--bew-theme-color) !important; + --bili-rich-text-link-color-hover: var(--bew-theme-color-80) !important; + + #contents img[src*="https://i0.hdslb.com/bfs/activity-plat/static/20201110/4c8b2dbaded282e67c9a31daa4297c3c/AeQJlYP7e.png"] + { + filter: var(--bew-filter-icon-glow); + } +} diff --git a/src/styles/variables.scss b/src/styles/variables.scss index 3339997b..2bcef83e 100644 --- a/src/styles/variables.scss +++ b/src/styles/variables.scss @@ -192,7 +192,8 @@ } :host(.dark), -:root.dark { +:root.dark, +.dark { // dark mode // #region shadow