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'); var style = localStorage.getItem('data-color-mode')
iconElement = document.getElementById('github-icon'); githubIconElement = document.getElementById('github-icon')
twitterIconElement = document.getElementById('twitter-icon'); twitterIconElement = document.getElementById('twitter-icon')
if (style == 'light') { if (style == 'light') {
if (iconElement) iconElement.setAttribute('fill', '#24292e'); if (githubIconElement) githubIconElement.setAttribute('fill', '#24292e')
if (twitterIconElement) twitterIconElement.setAttribute("fill","black") if (twitterIconElement) twitterIconElement.setAttribute('fill', 'black')
} }
else { else {
if (iconElement) { if (githubIconElement) {
iconElement.removeAttribute('fill'); githubIconElement.removeAttribute('fill')
iconElement.setAttribute('class', 'octicon'); githubIconElement.setAttribute('class', 'octicon')
iconElement.setAttribute('color', '#f0f6fc'); githubIconElement.setAttribute('color', '#f0f6fc')
} }
if (twitterIconElement) twitterIconElement.setAttribute("fill","white") if (twitterIconElement) twitterIconElement.setAttribute('fill', 'white')
} }
</script> </script>

View File

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