Update base.html

This commit is contained in:
Chua Song Ann 2024-01-04 17:26:06 +08:00 committed by sachua
parent 2ed0a6cafc
commit 7ce279cf15
1 changed files with 22 additions and 0 deletions

View File

@ -37,12 +37,14 @@ function changeDark(){
document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="dark";
document.getElementById("themeSwitch").setAttribute("d",value=IconList["moon"]);
document.getElementById("themeSwitch").parentNode.style.color="#00f0ff";
updateSourceMedia("dark");
if(utterancesLoad==1){utterancesTheme("dark-blue");}
}
function changeLight(){
document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="light";
document.getElementById("themeSwitch").setAttribute("d",value=IconList["sun"]);
document.getElementById("themeSwitch").parentNode.style.color="#ff5000";
updateSourceMedia("light");
if(utterancesLoad==1){utterancesTheme("github-light");}
}
function modeSwitch(){
@ -55,6 +57,26 @@ function utterancesTheme(theme){
iframe.contentWindow.postMessage(message, 'https://utteranc.es');
}
function updateSourceMedia(colorPreference) {
const pictures = document.querySelectorAll('picture')
pictures.forEach((picture) => {
const sources = picture.querySelectorAll(`
source[media*="prefers-color-scheme"],
source[data-media*="prefers-color-scheme"]
`)
sources.forEach((source) => {
if (source?.media.includes('prefers-color-scheme')) {
source.dataset.media = source.media
}
if (source?.dataset.media.includes(colorPreference)) {
source.media = 'all'
} else if (source) {
source.media = 'none'
}
})
})
}
console.log("\n %c Gmeek {{ blogBase['GMEEK_VERSION'] }} %c https://github.com/Meekdai/Gmeek \n\n", "color: #fff; background-image: linear-gradient(90deg, rgb(47, 172, 178) 0%, rgb(45, 190, 96) 100%); padding:5px 1px;", "background-image: linear-gradient(90deg, rgb(45, 190, 96) 0%, rgb(255, 255, 255) 100%); padding:5px 0;");
</script>
{% block script %}{% endblock %}