add the color setup

This commit is contained in:
Julien Calixte
2023-07-31 14:31:36 +02:00
parent b2eeb1c02b
commit 32030c4a25

51
main.ts
View File

@@ -1,28 +1,28 @@
type TPSSearchParams = { type TPSSearchParams = {
display?: "house-only" | "full" display?: 'house-only' | 'full'
} }
const params = new URL(document.location.href).searchParams const params = new URL(document.location.href).searchParams
const display = params.get("display") const display = params.get('display')
if (display === "house-only") { if (display === 'house-only') {
document.querySelector("header")?.remove() document.querySelector('header')?.remove()
} }
const size = params.get("size") const size = params.get('size')
if (size === "small") { if (size === 'small') {
const body = document.querySelector("body") const body = document.querySelector('body')
if (body) { if (body) {
body.style.fontSize = "15px" body.style.fontSize = '15px'
} }
} }
const focusElements = params.getAll("focus") const focusElements = params.getAll('focus')
if (focusElements.length > 0) { if (focusElements.length > 0) {
const focusables = document.querySelectorAll(".focusable") const focusables = document.querySelectorAll('.focusable')
focusables.forEach((focusable) => { focusables.forEach((focusable) => {
const elementToFocus = focusElements.some((element) => const elementToFocus = focusElements.some((element) =>
@@ -30,20 +30,35 @@ if (focusElements.length > 0) {
) )
if (!elementToFocus) { if (!elementToFocus) {
focusable.classList.add("no-focus") focusable.classList.add('no-focus')
} }
}) })
} }
const textHide = params.get("text") const textHide = params.get('text')
if (textHide === "hide") { if (textHide === 'hide') {
const focusables = document.querySelectorAll(".focusable") const focusables = document.querySelectorAll('.focusable')
focusables.forEach((focusable) => focusable.classList.add("text-hide")) focusables.forEach((focusable) => focusable.classList.add('text-hide'))
} }
const scrollParam = params.get("scroll") const scrollParam = params.get('scroll')
if (scrollParam === "end") { if (scrollParam === 'end') {
window.scrollTo({ top: document.body.scrollHeight, behavior: "smooth" }) window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' })
}
const primaryColorParam = params.get('primary')
if (primaryColorParam) {
document.documentElement.style.setProperty(
'--primary-color',
`#${primaryColorParam}`
)
}
const colorParam = params.get('color')
if (colorParam) {
document.documentElement.style.setProperty('--color', `#${colorParam}`)
} }