-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
a902b46
commit cfe66c5
Showing
5 changed files
with
52 additions
and
18 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
;(() => { | ||
const targetElement = document.documentElement; | ||
const defaultTheme = targetElement.getAttribute("data-color-mode"); | ||
changeGiscusTheme(defaultTheme) | ||
const observer = new MutationObserver((mutationsList, observer) => { | ||
for(const mutation of mutationsList) { | ||
if (mutation.type === 'attributes') { | ||
const value = targetElement.getAttribute("data-color-mode"); | ||
changeGiscusTheme(value) | ||
} | ||
} | ||
}); | ||
|
||
observer.observe(targetElement, { | ||
attributes: true, | ||
attributeOldValue: true | ||
}); | ||
|
||
function changeGiscusTheme(theme = "light") { | ||
const iframe = document.querySelector('.giscus-frame'); | ||
if (iframe) { | ||
const config = { | ||
giscus: { | ||
setConfig: { | ||
theme: theme.toLocaleLowerCase(), | ||
}, | ||
} | ||
}; | ||
iframe.contentWindow.postMessage(config, 'https://giscus.app'); | ||
const script = document.querySelector("script[data-script-id=\"giscus\"]") | ||
script.setAttribute("data-theme", theme) | ||
} | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters