This commit is contained in:
yuweizzz
2024-07-03 23:20:53 +08:00
parent 5c406167ff
commit 55ce7307c0
2 changed files with 31 additions and 28 deletions

View File

@@ -204,19 +204,19 @@ window.onscroll = function (e) {
}
};
var style = localStorage.getItem('data-color-mode');
iconElement = document.getElementById('github-icon');
twitterIconElement = document.getElementById('twitter-icon');
var style = localStorage.getItem('data-color-mode')
githubIconElement = document.getElementById('github-icon')
twitterIconElement = document.getElementById('twitter-icon')
if (style == 'light') {
if (iconElement) iconElement.setAttribute('fill', '#24292e');
if (twitterIconElement) twitterIconElement.setAttribute("fill","black")
if (githubIconElement) githubIconElement.setAttribute('fill', '#24292e')
if (twitterIconElement) twitterIconElement.setAttribute('fill', 'black')
}
else {
if (iconElement) {
iconElement.removeAttribute('fill');
iconElement.setAttribute('class', 'octicon');
iconElement.setAttribute('color', '#f0f6fc');
if (githubIconElement) {
githubIconElement.removeAttribute('fill')
githubIconElement.setAttribute('class', 'octicon')
githubIconElement.setAttribute('color', '#f0f6fc')
}
if (twitterIconElement) twitterIconElement.setAttribute("fill","white")
if (twitterIconElement) twitterIconElement.setAttribute('fill', 'white')
}
</script>

View File

@@ -1,22 +1,12 @@
function switchTheme() {
const currentStyle = currentTheme();
const iconElement = document.getElementById('github-icon');
const currentStyle = currentTheme()
if (currentStyle === 'light') {
setTheme('dark');
setTheme('dark')
setIconTheme('dark')
if (iconElement) {
iconElement.setAttribute('class', 'octicon');
iconElement.setAttribute('color', '#f0f6fc');
}
}
else {
setTheme('light');
setTheme('light')
setIconTheme('light')
if (iconElement) {
iconElement.removeAttribute('color');
iconElement.removeAttribute('class');
}
}
}
@@ -29,11 +19,24 @@ function setTheme(style) {
}
function setIconTheme(theme) {
twitterIconElement = document.getElementById('twitter-icon');
if (theme === 'light') {
twitterIconElement.setAttribute("fill", "black")
} else if (theme === 'dark') {
twitterIconElement.setAttribute("fill", "white")
const twitterIconElement = document.getElementById('twitter-icon')
const githubIconElement = document.getElementById('github-icon')
if (twitterIconElement) {
if (theme === 'light') {
twitterIconElement.setAttribute("fill", "black")
} else if (theme === 'dark') {
twitterIconElement.setAttribute("fill", "white")
}
}
if (githubIconElement) {
if (theme === 'light') {
githubIconElement.removeAttribute('color')
githubIconElement.removeAttribute('class')
} else if (theme === 'dark') {
githubIconElement.setAttribute('class', 'octicon')
githubIconElement.setAttribute('color', '#f0f6fc')
}
}
}