Skip to content

Commit

Permalink
2021-05-08 22:39:09
Browse files Browse the repository at this point in the history
  • Loading branch information
wizardforcel committed May 8, 2021
1 parent 128b781 commit 4bc4553
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
23 changes: 23 additions & 0 deletions asset/dark-mode.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#dark-mode-btn {
position: fixed;
right: 20px;
top: 100px;
width: 25px;
height: 25px;
background-repeat: no-repeat;
background-size: cover;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
transition: background-image .15s ease-in-out .15s;
}

.dark-logo {
background-image: url('sun.svg');
}

.light-logo {
background-image: url('moon.svg');
}
42 changes: 42 additions & 0 deletions asset/dark-mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
document.addEventListener('DOMContentLoaded', function() {
var style = document.querySelector('#invert')
if (style == null) {
style = document.createElement('style')
style.id = 'invert'
document.head.append(style)
}
var btn = document.querySelector('#dark-mode-btn')
if (btn == null) {
btn = document.createElement('div')
btn.id = 'dark-mode-btn'
btn.classList.add('light-logo')
document.body.append(btn)
}

var enableDarkMode = function() {
style.innerText = 'html,img,pre,#dark-mode-btn{filter:invert(100%)}'
btn.classList.remove('light-logo')
btn.classList.add('dark-logo')
localStorage.darkLight = 'dark'

}
var disableDarkMode = function() {
style.innerText = ''
btn.classList.remove('dark-logo')
btn.classList.add('light-logo')
localStorage.darkLight = 'light'
}

btn.addEventListener('click', function(){
var currMode = localStorage.darkLight || 'light'
if (currMode == 'light')
enableDarkMode()
else
disableDarkMode()
})

if (localStorage.darkLight == 'dark')
enableDarkMode()

})

1 change: 1 addition & 0 deletions asset/moon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions asset/sun.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

<!-- google webmaster -->
<meta name="google-site-verification" content="pyo9N70ZWyh8JB43bIu633mhxesJ1IcwWCZlM3jUfFo" />

<link rel="stylesheet" href="asset/dark-mode.css">
<script src="asset/dark-mode.js"></script>
</head>
<body>
<div id="app">now loading...</div>
Expand Down Expand Up @@ -57,6 +60,5 @@
<script src="asset/docsify-cnzz.js"></script>
<script src="asset/docsify-apachecn-footer.js"></script>
<script src="asset/docsify-clicker.js"></script>
<script src="asset/docsify-clicker.js"></script>
</body>
</html>

0 comments on commit 4bc4553

Please sign in to comment.