2018-04-14 23:50:16 +01: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.
|
2018-09-23 20:26:01 +01:00
|
|
|
window.__themeColors = process.env.THEME_COLORS
|
|
|
|
|
2018-04-14 23:50:16 +01:00
|
|
|
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 08:33:42 +01:00
|
|
|
if (theme && theme !== 'default') {
|
2018-04-14 23:50:16 +01:00
|
|
|
let link = document.createElement('link')
|
|
|
|
link.rel = 'stylesheet'
|
|
|
|
link.href = `/theme-${theme}.css`
|
2018-11-24 08:41:36 +00:00
|
|
|
// inserting before the offline <style> ensures that the offline style wins when offline
|
|
|
|
document.head.insertBefore(link, document.getElementById('theOfflineStyle'))
|
2018-04-14 23:50:16 +01:00
|
|
|
if (window.__themeColors[theme]) {
|
|
|
|
document.getElementById('theThemeColor').content = window.__themeColors[theme]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 20:26:01 +01:00
|
|
|
|
2018-04-14 23:50:16 +01:00
|
|
|
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 07:14:30 +01:00
|
|
|
|
2018-11-28 03:17:18 +00:00
|
|
|
if (localStorage.store_disableCustomScrollbars === 'true') {
|
|
|
|
// if user has disabled custom scrollbars, remove this style
|
|
|
|
let theScrollbarStyle = document.getElementById('theScrollbarStyle')
|
|
|
|
theScrollbarStyle.setAttribute('media', 'only x') // disables the style
|
|
|
|
}
|
|
|
|
|
|
|
|
// hack to make the scrollbars rounded only on macOS
|
|
|
|
if (/mac/i.test(navigator.platform)) {
|
|
|
|
document.documentElement.style.setProperty('--scrollbar-border-radius', '50px')
|
|
|
|
}
|
|
|
|
|
2018-08-19 07:14:30 +01: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'))
|
|
|
|
}
|