2021-07-05 03:19:04 +00:00
|
|
|
import { switchToTheme } from '../../_utils/themeEngine.js'
|
2019-06-01 20:07:31 +00:00
|
|
|
|
2019-06-01 22:51:46 +00:00
|
|
|
const style = process.browser && document.getElementById('theGrayscaleStyle')
|
|
|
|
|
2019-06-01 20:07:31 +00:00
|
|
|
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
|
2019-06-01 20:07:31 +00:00
|
|
|
switchToTheme(theme, enableGrayscale)
|
2022-11-19 19:25:42 +00:00
|
|
|
}, { init: false }) // init:false because the inline script takes care of it
|
2019-06-01 20:07:31 +00:00
|
|
|
}
|