From b9ae39eab9773fa6ccce2c45ca608caa89aabe0c Mon Sep 17 00:00:00 2001 From: Sodbileg Gansukh Date: Mon, 3 Jun 2024 17:19:03 +0800 Subject: [PATCH] Made the background color calculation compatible with shortened hex value --- default.hbs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/default.hbs b/default.hbs index e760532..f27a888 100644 --- a/default.hbs +++ b/default.hbs @@ -26,6 +26,11 @@ https://gomakethings.com/dynamically-changing-the-text-color-based-on-background-color-contrast-with-vanilla-js/ */ var accentColor = getComputedStyle(document.documentElement).getPropertyValue('--background-color'); accentColor = accentColor.trim().slice(1); + + if (accentColor.length === 3) { + accentColor = accentColor[0] + accentColor[0] + accentColor[1] + accentColor[1] + accentColor[2] + accentColor[2]; + } + var r = parseInt(accentColor.substr(0, 2), 16); var g = parseInt(accentColor.substr(2, 2), 16); var b = parseInt(accentColor.substr(4, 2), 16);