2018-04-14 22:50:16 +00:00
|
|
|
// For perf reasons, this script is run inline to quickly set certain styles.
|
|
|
|
// To allow CSP to work correctly, we also calculate a sha256 hash during
|
|
|
|
// the build process and write it to inline-script-checksum.json.
|
|
|
|
window.__themeColors = {
|
|
|
|
'default': 'royalblue',
|
|
|
|
scarlet: '#e04e41',
|
|
|
|
seafoam: '#177380',
|
|
|
|
hotpants: 'hotpink',
|
|
|
|
oaken: 'saddlebrown',
|
|
|
|
majesty: 'blueviolet',
|
|
|
|
gecko: '#4ab92f',
|
|
|
|
ozark: '#5263af',
|
|
|
|
cobalt: '#08439b',
|
|
|
|
sorcery: '#ae91e8',
|
2018-09-22 23:42:18 +00:00
|
|
|
punk: '#e04e41',
|
|
|
|
riot: 'hotpink',
|
2018-09-06 02:22:20 +00:00
|
|
|
hacker: '#4ab92f',
|
2018-04-14 22:50:16 +00:00
|
|
|
offline: '#999999'
|
|
|
|
}
|
|
|
|
if (localStorage.store_currentInstance && localStorage.store_instanceThemes) {
|
|
|
|
let safeParse = (str) => str === 'undefined' ? undefined : JSON.parse(str)
|
|
|
|
let theme = safeParse(localStorage.store_instanceThemes)[safeParse(localStorage.store_currentInstance)]
|
2018-04-21 07:33:42 +00:00
|
|
|
if (theme && theme !== 'default') {
|
2018-04-14 22:50:16 +00:00
|
|
|
document.body.classList.add(`theme-${theme}`)
|
|
|
|
let link = document.createElement('link')
|
|
|
|
link.rel = 'stylesheet'
|
|
|
|
link.href = `/theme-${theme}.css`
|
|
|
|
document.head.appendChild(link)
|
|
|
|
if (window.__themeColors[theme]) {
|
|
|
|
document.getElementById('theThemeColor').content = window.__themeColors[theme]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!localStorage.store_currentInstance) {
|
|
|
|
// if not logged in, show all these 'hidden-from-ssr' elements
|
|
|
|
let style = document.createElement('style')
|
|
|
|
style.textContent = '.hidden-from-ssr { opacity: 1 !important; }'
|
|
|
|
document.head.appendChild(style)
|
|
|
|
}
|
2018-08-19 06:14:30 +00:00
|
|
|
|
|
|
|
// TODO: remove this hack when Safari works with cross-origin window.open()
|
|
|
|
// in a PWA: https://github.com/nolanlawson/pinafore/issues/45
|
|
|
|
if (/iP(?:hone|ad|od)/.test(navigator.userAgent)) {
|
|
|
|
document.head.removeChild(document.getElementById('theManifest'))
|
|
|
|
}
|