fix: check if is color before changing colors

This commit is contained in:
Julien Calixte
2025-02-23 22:52:43 +01:00
parent ee48a2907c
commit cabc887814
3 changed files with 23 additions and 2 deletions

View File

@@ -1,4 +1,7 @@
import { domToPng } from 'modern-screenshot'
import hexColorRegex from 'hex-color-regex'
const isColor = (color: string) => hexColorRegex().test(color)
const params = new URL(document.location.href).searchParams
@@ -62,7 +65,7 @@ if (textHide === 'hide') {
const primaryColorParam = params.get('primary')
if (primaryColorParam) {
if (primaryColorParam && isColor(`#${primaryColorParam}`)) {
document.documentElement.style.setProperty(
'--primary-color',
`#${primaryColorParam}`
@@ -71,7 +74,7 @@ if (primaryColorParam) {
const colorParam = params.get('color')
if (colorParam) {
if (colorParam && isColor(`#${colorParam}`)) {
document.documentElement.style.setProperty('--color', `#${colorParam}`)
}