Répare le prérendu côté serveur

pull/2799/head
Johan Girod 2023-09-13 09:40:36 +02:00
parent fefe90a1b5
commit e023090ca7
1 changed files with 22 additions and 13 deletions

View File

@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="{{lang}}">
<head>
<meta charset="utf-8" />
@ -154,16 +154,16 @@
</div>
<script>
const isIframe = document.location.pathname.startsWith(/iframes/')
const isIframe = document.location.pathname.startsWith('/iframes/')
function getItem(key) {
try {
return window.localStorage.getItem(key)
} catch (error) {
if (error instanceof Error && error.name === SecurityError) {
if (error instanceof Error && error.name === 'SecurityError') {
// eslint-disable-next-line no-console
console.warn(
'[localStorage] Unable to set item due to security settings
'[localStorage] Unable to set item due to security settings'
)
}
@ -171,20 +171,29 @@
}
}
const darkMode = !isIframe && getItem(darkMode) === true
const darkMode = !isIframe && getItem('darkMode') === 'true'
if (darkMode) {
document.body.style.backgroundColor = '#0f172a
const styleEl = document.createElement('style')
document.head.appendChild(styleEl)
styleEl.sheet.insertRule(
'body * { background-color: #0f172a !important; color: white !important; border-color: white }',
0
)
addEventListener('load', (event) => {
document.head.removeChild(styleEl)
})
}
</script>
<!-- USER AGENT DATA ATTRIBUTE -->
<script>
var b = document.documentElement
b.setAttribute(data-useragent, navigator.userAgent)
b.setAttribute('data-useragent', navigator.userAgent)
</script>
<script>
console.log('YIPIEYAE')
// Set the main colors from the provided customization in the URL We do it
// before loading the whole JS bundle to avoid a UI flash. cf. #1786
function parseColor(rawColor) {
@ -199,19 +208,19 @@
try {
const rawColor = new URLSearchParams(
document.location.search.substring(1)
).get(couleur)
).get('couleur')
const iframeColor = rawColor && parseColor(rawColor)
;[
document.documentElement,
…document.querySelectorAll([data-js-color-element]'),
...document.querySelectorAll('[data-js-color-element]'),
].forEach((element) => {
element.style.setProperty(
'--COLOR_HUE,
iframeColor ? iframeColor[0] : 220deg
'--COLOR_HUE',
iframeColor ? iframeColor[0] : '220deg'
)
element.style.setProperty(
'--COLOR_SATURATION,
iframeColor ? iframeColor[1] + '% : 100%
'--COLOR_SATURATION',
iframeColor ? iframeColor[1] + '%' : '100%'
)
})
} catch (e) {