pinafore/src/routes/_store/observers/grayscaleObservers.js

17 wiersze
633 B
JavaScript
Czysty Zwykły widok Historia

import { switchToTheme } from '../../_utils/themeEngine.js'
2019-06-01 22:51:46 +00:00
const style = process.browser && document.getElementById('theGrayscaleStyle')
export function grayscaleObservers (store) {
if (!process.browser) {
return
}
store.observe('enableGrayscale', enableGrayscale => {
const { instanceThemes, currentInstance } = store.get()
const theme = instanceThemes && instanceThemes[currentInstance]
2019-06-01 22:51:46 +00:00
style.setAttribute('media', enableGrayscale ? 'all' : 'only x') // disable or enable the style
switchToTheme(theme, enableGrayscale)
}, { init: false }) // init:false because the inline script takes care of it
}