2023-01-14 12:34:53 +03:00
|
|
|
import { STORAGE_KEY_CURRENT_USER_HANDLE, STORAGE_KEY_SETTINGS } from '~/constants'
|
2023-01-22 23:18:03 +03:00
|
|
|
import { oldFontSizeMap } from '~/constants/options'
|
2023-01-14 12:34:53 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2023-01-16 13:26:19 +03:00
|
|
|
const html = document.documentElement
|
2024-02-24 19:46:14 +03:00
|
|
|
${import.meta.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-22 23:18:03 +03:00
|
|
|
const oldFontSizeMap = ${JSON.stringify(oldFontSizeMap)}
|
|
|
|
html.style.setProperty('--font-size', oldFontSizeMap[settings.fontSize] || 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)
|
|
|
|
}
|
2023-04-23 13:21:33 +03:00
|
|
|
if (settings.preferences.zenMode) {
|
2023-01-14 13:09:17 +03:00
|
|
|
html.classList.add('zen')
|
2023-01-14 12:34:53 +03:00
|
|
|
}
|
2023-01-16 13:26:19 +03:00
|
|
|
if (settings.themeColors) {
|
|
|
|
Object.entries(settings.themeColors).map(i => html.style.setProperty(i[0], i[1]))
|
|
|
|
}
|
2023-01-14 12:34:53 +03:00
|
|
|
})()`.trim().replace(/\s*\n+\s*/g, ';'),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
})
|