mirror of
https://github.com/13hannes11/hugo-coder-timeline.git
synced 2024-09-04 00:50:58 +02:00
dynamic change utterances theme with coder theme (#676)
* dynamic change utterances theme with coder theme * add myself into CONTRIBUTORS.md
This commit is contained in:
@@ -34,6 +34,48 @@ function setTheme(theme) {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user