精简changeTheme函数
This commit is contained in:
parent
a15d7932d9
commit
a548882b31
1
Gmeek.py
1
Gmeek.py
@ -263,7 +263,6 @@ class GMEEK():
|
||||
listJsonName='singeListJson'
|
||||
htmlFile='{}.html'.format(self.createFileName(issue,useLabel=True))
|
||||
gen_Html = self.root_dir+htmlFile
|
||||
|
||||
else:
|
||||
listJsonName='postListJson'
|
||||
htmlFile='{}.html'.format(self.createFileName(issue))
|
||||
|
||||
@ -8,10 +8,8 @@
|
||||
<link rel="icon" href="{{ blogBase['faviconUrl'] }}">
|
||||
{%- if blogBase['themeMode']=='manual' -%}
|
||||
<script>
|
||||
if(localStorage.getItem("meek_theme")==null){}
|
||||
else if(localStorage.getItem("meek_theme")=="dark"){document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="dark";}
|
||||
else if(localStorage.getItem("meek_theme")=="light"){document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="light";}
|
||||
else {document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="auto";}
|
||||
let theme = localStorage.getItem("meek_theme");
|
||||
if(theme !== null) {document.documentElement.setAttribute("data-color-mode", theme);}
|
||||
</script>
|
||||
{%- endif -%}
|
||||
{% block head %}{% endblock %}
|
||||
@ -32,44 +30,37 @@ body{box-sizing: border-box;min-width: 200px;max-width: 900px;margin: 20px auto;
|
||||
<script>
|
||||
var IconList={{ IconList }};
|
||||
var utterancesLoad=0;
|
||||
{%- if blogBase['themeMode']=='manual' -%}
|
||||
if(localStorage.getItem("meek_theme")==null){localStorage.setItem("meek_theme","light");changeLight();}
|
||||
else if(localStorage.getItem("meek_theme")=="dark"){changeDark();}
|
||||
else if(localStorage.getItem("meek_theme")=="light"){changeLight();}
|
||||
else if(localStorage.getItem("meek_theme")=="auto"){changeAuto();}
|
||||
|
||||
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";
|
||||
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";
|
||||
if(utterancesLoad==1){utterancesTheme("github-light");}
|
||||
}
|
||||
function changeAuto(){
|
||||
document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="auto";
|
||||
document.getElementById("themeSwitch").setAttribute("d",value=IconList["sync"]);
|
||||
document.getElementById("themeSwitch").parentNode.style.color="";
|
||||
if(utterancesLoad==1){utterancesTheme("preferred-color-scheme");}
|
||||
{% if blogBase['themeMode']=='manual' %}
|
||||
let themeSettings={
|
||||
"dark": ["dark","moon","#00f0ff","dark-blue"],
|
||||
"light": ["light","sun","#ff5000","github-light"],
|
||||
"auto": ["auto","sync","","preferred-color-scheme"]
|
||||
};
|
||||
function changeTheme(mode, icon, color, utheme){
|
||||
document.documentElement.setAttribute("data-color-mode",mode);
|
||||
document.getElementById("themeSwitch").setAttribute("d",value=IconList[icon]);
|
||||
document.getElementById("themeSwitch").parentNode.style.color=color;
|
||||
if(utterancesLoad==1){utterancesTheme(utheme);}
|
||||
}
|
||||
function modeSwitch(){
|
||||
if(document.getElementsByTagName("html")[0].attributes[0].value=="light"){changeDark();localStorage.setItem("meek_theme","dark");}
|
||||
else if(document.getElementsByTagName("html")[0].attributes[0].value=="dark"){changeAuto();localStorage.setItem("meek_theme","auto");}
|
||||
else{changeLight();localStorage.setItem("meek_theme","light");}
|
||||
let currentMode=document.documentElement.getAttribute('data-color-mode');
|
||||
let newMode = currentMode === "light" ? "dark" : currentMode === "dark" ? "auto" : "light";
|
||||
localStorage.setItem("meek_theme", newMode);
|
||||
if(themeSettings[newMode]){
|
||||
changeTheme(...themeSettings[newMode]);
|
||||
}
|
||||
}
|
||||
|
||||
function utterancesTheme(theme){
|
||||
const message={type:'set-theme',theme: theme};
|
||||
const iframe=document.getElementsByClassName('utterances-frame')[0];
|
||||
iframe.contentWindow.postMessage(message,'https://utteranc.es');
|
||||
}
|
||||
{%- endif -%}
|
||||
|
||||
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;");
|
||||
let theme=localStorage.getItem("meek_theme") || "light";
|
||||
localStorage.setItem("meek_theme", theme);
|
||||
if(themeSettings[theme]){changeTheme(...themeSettings[theme]);}
|
||||
{%- endif %}
|
||||
console.log("\n %c Gmeek {{ blogBase['GMEEK_VERSION'] }} https://github.com/Meekdai/Gmeek \n\n","padding:5px 0;background:#02d81d;color:#fff");
|
||||
</script>
|
||||
{% block script %}{% endblock %}
|
||||
{{ blogBase['script'] }}
|
||||
|
||||
@ -69,7 +69,6 @@ document.getElementById("pathIssue").setAttribute("d",IconList["github"]);
|
||||
span.innerHTML="{{ blogBase['commentNum'] }}";
|
||||
cmButton.appendChild(span);
|
||||
{%- endif %}
|
||||
|
||||
function openComments(){
|
||||
cm=document.getElementById("comments");
|
||||
cmButton=document.getElementById("cmButton");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user