fix: check if is color before changing colors
This commit is contained in:
7
main.ts
7
main.ts
@@ -1,4 +1,7 @@
|
|||||||
import { domToPng } from 'modern-screenshot'
|
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
|
const params = new URL(document.location.href).searchParams
|
||||||
|
|
||||||
@@ -62,7 +65,7 @@ if (textHide === 'hide') {
|
|||||||
|
|
||||||
const primaryColorParam = params.get('primary')
|
const primaryColorParam = params.get('primary')
|
||||||
|
|
||||||
if (primaryColorParam) {
|
if (primaryColorParam && isColor(`#${primaryColorParam}`)) {
|
||||||
document.documentElement.style.setProperty(
|
document.documentElement.style.setProperty(
|
||||||
'--primary-color',
|
'--primary-color',
|
||||||
`#${primaryColorParam}`
|
`#${primaryColorParam}`
|
||||||
@@ -71,7 +74,7 @@ if (primaryColorParam) {
|
|||||||
|
|
||||||
const colorParam = params.get('color')
|
const colorParam = params.get('color')
|
||||||
|
|
||||||
if (colorParam) {
|
if (colorParam && isColor(`#${colorParam}`)) {
|
||||||
document.documentElement.style.setProperty('--color', `#${colorParam}`)
|
document.documentElement.style.setProperty('--color', `#${colorParam}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
"@vueuse/core": "^12.2.0",
|
"@vueuse/core": "^12.2.0",
|
||||||
"chart.xkcd": "^1.1.15",
|
"chart.xkcd": "^1.1.15",
|
||||||
"comlink": "^4.4.2",
|
"comlink": "^4.4.2",
|
||||||
|
"hex-color-regex": "^1.1.0",
|
||||||
"modern-screenshot": "^4.5.5",
|
"modern-screenshot": "^4.5.5",
|
||||||
"pinia": "^2.3.1",
|
"pinia": "^2.3.1",
|
||||||
"random-js": "^2.1.0",
|
"random-js": "^2.1.0",
|
||||||
@@ -26,6 +27,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@faker-js/faker": "^9.4.0",
|
"@faker-js/faker": "^9.4.0",
|
||||||
|
"@types/hex-color-regex": "^1.1.3",
|
||||||
"@types/node": "^22.10.2",
|
"@types/node": "^22.10.2",
|
||||||
"@vitejs/plugin-vue": "^5.2.1",
|
"@vitejs/plugin-vue": "^5.2.1",
|
||||||
"sass": "^1.85.0",
|
"sass": "^1.85.0",
|
||||||
|
|||||||
16
pnpm-lock.yaml
generated
16
pnpm-lock.yaml
generated
@@ -17,6 +17,9 @@ importers:
|
|||||||
comlink:
|
comlink:
|
||||||
specifier: ^4.4.2
|
specifier: ^4.4.2
|
||||||
version: 4.4.2
|
version: 4.4.2
|
||||||
|
hex-color-regex:
|
||||||
|
specifier: ^1.1.0
|
||||||
|
version: 1.1.0
|
||||||
modern-screenshot:
|
modern-screenshot:
|
||||||
specifier: ^4.5.5
|
specifier: ^4.5.5
|
||||||
version: 4.5.5
|
version: 4.5.5
|
||||||
@@ -36,6 +39,9 @@ importers:
|
|||||||
'@faker-js/faker':
|
'@faker-js/faker':
|
||||||
specifier: ^9.4.0
|
specifier: ^9.4.0
|
||||||
version: 9.4.0
|
version: 9.4.0
|
||||||
|
'@types/hex-color-regex':
|
||||||
|
specifier: ^1.1.3
|
||||||
|
version: 1.1.3
|
||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^22.10.2
|
specifier: ^22.10.2
|
||||||
version: 22.10.2
|
version: 22.10.2
|
||||||
@@ -647,6 +653,9 @@ packages:
|
|||||||
'@types/estree@1.0.6':
|
'@types/estree@1.0.6':
|
||||||
resolution: {integrity: sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==}
|
resolution: {integrity: sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==}
|
||||||
|
|
||||||
|
'@types/hex-color-regex@1.1.3':
|
||||||
|
resolution: {integrity: sha512-xOvT3NwAinCRD0knfP5wRVWGCUmQVtYO6TDMzLeVlUckdDvNOSgNCNGWmSbFde/Ll42QM6YQ4qHkrOpdhU3aVg==}
|
||||||
|
|
||||||
'@types/node@22.10.2':
|
'@types/node@22.10.2':
|
||||||
resolution: {integrity: sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ==}
|
resolution: {integrity: sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ==}
|
||||||
|
|
||||||
@@ -862,6 +871,9 @@ packages:
|
|||||||
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
|
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
|
||||||
os: [darwin]
|
os: [darwin]
|
||||||
|
|
||||||
|
hex-color-regex@1.1.0:
|
||||||
|
resolution: {integrity: sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==}
|
||||||
|
|
||||||
immutable@5.0.3:
|
immutable@5.0.3:
|
||||||
resolution: {integrity: sha512-P8IdPQHq3lA1xVeBRi5VPqUm5HDgKnx0Ru51wZz5mjxHr5n3RWhjIpOFU7ybkUxfB+5IToy+OLaHYDBIWsv+uw==}
|
resolution: {integrity: sha512-P8IdPQHq3lA1xVeBRi5VPqUm5HDgKnx0Ru51wZz5mjxHr5n3RWhjIpOFU7ybkUxfB+5IToy+OLaHYDBIWsv+uw==}
|
||||||
|
|
||||||
@@ -1486,6 +1498,8 @@ snapshots:
|
|||||||
|
|
||||||
'@types/estree@1.0.6': {}
|
'@types/estree@1.0.6': {}
|
||||||
|
|
||||||
|
'@types/hex-color-regex@1.1.3': {}
|
||||||
|
|
||||||
'@types/node@22.10.2':
|
'@types/node@22.10.2':
|
||||||
dependencies:
|
dependencies:
|
||||||
undici-types: 6.20.0
|
undici-types: 6.20.0
|
||||||
@@ -1787,6 +1801,8 @@ snapshots:
|
|||||||
fsevents@2.3.3:
|
fsevents@2.3.3:
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
|
hex-color-regex@1.1.0: {}
|
||||||
|
|
||||||
immutable@5.0.3: {}
|
immutable@5.0.3: {}
|
||||||
|
|
||||||
internmap@1.0.1: {}
|
internmap@1.0.1: {}
|
||||||
|
|||||||
Reference in New Issue
Block a user