| | |
| | | body.classList.remove('colorscheme-' + inverse); |
| | | body.classList.add('colorscheme-' + theme); |
| | | document.documentElement.style['color-scheme'] = theme; |
| | | |
| | | function waitForElm(selector) { |
| | | return new Promise(resolve => { |
| | | if (document.querySelector(selector)) { |
| | | return resolve(document.querySelector(selector)); |
| | | } |
| | | |
| | | const observer = new MutationObserver(mutations => { |
| | | if (document.querySelector(selector)) { |
| | | resolve(document.querySelector(selector)); |
| | | observer.disconnect(); |
| | | } |
| | | }); |
| | | |
| | | observer.observe(document.body, { |
| | | childList: true, |
| | | subtree: true |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | if (theme === 'dark') { |
| | | const message = { |
| | | type: 'set-theme', |
| | | theme: 'github-dark' |
| | | }; |
| | | waitForElm('.utterances-frame').then((iframe) => { |
| | | iframe.contentWindow.postMessage(message, 'https://utteranc.es'); |
| | | }) |
| | | |
| | | } |
| | | else { |
| | | const message = { |
| | | type: 'set-theme', |
| | | theme: 'github-light' |
| | | }; |
| | | waitForElm('.utterances-frame').then((iframe) => { |
| | | iframe.contentWindow.postMessage(message, 'https://utteranc.es'); |
| | | }) |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | function rememberTheme(theme) { |