2023-01-14 12:34:53 +03:00
|
|
|
import { STORAGE_KEY_CURRENT_USER_HANDLE, STORAGE_KEY_SETTINGS } from '~/constants'
|
|
|
|
import { fontSizeMap } from '~/constants/options'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Injecting scripts before renders
|
|
|
|
*/
|
|
|
|
export default defineNuxtPlugin(() => {
|
|
|
|
useHead({
|
|
|
|
script: [
|
|
|
|
{
|
|
|
|
innerHTML: `
|
|
|
|
;(function() {
|
2023-01-15 18:15:03 +03:00
|
|
|
const handle = localStorage.getItem('${STORAGE_KEY_CURRENT_USER_HANDLE}') || '[anonymous]'
|
2023-01-14 12:34:53 +03:00
|
|
|
const allSettings = JSON.parse(localStorage.getItem('${STORAGE_KEY_SETTINGS}') || '{}')
|
|
|
|
const settings = allSettings[handle]
|
2023-01-14 12:55:09 +03:00
|
|
|
if (!settings) { return }
|
2023-01-14 12:34:53 +03:00
|
|
|
|
|
|
|
const html = document.querySelector('html')
|
2023-01-14 12:55:09 +03:00
|
|
|
${process.dev ? 'console.log({ settings })' : ''}
|
2023-01-14 12:34:53 +03:00
|
|
|
|
2023-01-14 13:09:17 +03:00
|
|
|
if (settings.fontSize) {
|
2023-01-14 12:34:53 +03:00
|
|
|
const fontSizeMap = ${JSON.stringify(fontSizeMap)}
|
2023-01-14 13:09:17 +03:00
|
|
|
html.style.setProperty('--font-size', fontSizeMap[settings.fontSize])
|
2023-01-14 12:34:53 +03:00
|
|
|
}
|
2023-01-14 13:09:17 +03:00
|
|
|
if (settings.language) {
|
|
|
|
html.setAttribute('lang', settings.language)
|
|
|
|
}
|
|
|
|
if (settings.zenMode) {
|
|
|
|
html.classList.add('zen')
|
2023-01-14 12:34:53 +03:00
|
|
|
}
|
|
|
|
})()`.trim().replace(/\s*\n+\s*/g, ';'),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
})
|