Files
ReZygisk/webroot/js/switcher/fontChanger.js
ThePedroo 6ec8b5e7bd fix: JS code indentation/syntax
This commit fixes the syntax and indentation of the JavaScript code to meet the organization standard.
2024-11-12 00:09:10 -03:00

34 lines
955 B
JavaScript

const switcher = document.getElementById('font_switcher')
const rootCss = document.querySelector(':root')
let sys_font = localStorage.getItem('/system/font')
if (!sys_font) sys_font = setData('false')
if (sys_font === 'true') {
switcher.setAttribute('checked', '')
setSystemFont()
}
switcher.addEventListener('click', () => {
sys_font = setData(String(switcher.checked))
switcher.checked ? setSystemFont() : document.getElementById('font-tag').remove()
})
function setSystemFont() {
const headTag = document.getElementsByTagName('head')[0]
const styleTag = document.createElement('style')
styleTag.id = 'font-tag'
headTag.appendChild(styleTag)
styleTag.innerHTML = `
:root {
--font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif
}`
}
function setData(mode) {
localStorage.setItem('/system/font', mode)
return mode
}