fix(controller): isMainContentDark too aggressive

This commit is contained in:
Simon
2026-04-02 17:03:20 +08:00
committed by Shijie Sun
parent cc33297cc4
commit c6f09375f8

View File

@@ -138,15 +138,18 @@ function isTextColorLight() {
* @returns {boolean} * @returns {boolean}
*/ */
function isMainContentDark() { function isMainContentDark() {
const { innerWidth: vw, innerHeight: vh } = window
const minArea = vw * vh * 0.5
const selectors = ['main', '#app', '#root', '#__next', '[role="main"]'] const selectors = ['main', '#app', '#root', '#__next', '[role="main"]']
for (const selector of selectors) { for (const selector of selectors) {
const el = document.querySelector(selector) const el = document.querySelector(selector)
if (!el) continue if (!el) continue
const style = window.getComputedStyle(el) const rect = el.getBoundingClientRect()
if (isColorDark(style.backgroundColor)) { if (rect.width * rect.height < minArea) continue
return true
} if (isColorDark(window.getComputedStyle(el).backgroundColor)) return true
} }
return false return false
} }