diff --git a/asset/dark-mode.css b/asset/dark-mode.css new file mode 100644 index 0000000000000000000000000000000000000000..460957c6334d17e0bf8ba66a4a59b94f3164bf3e --- /dev/null +++ b/asset/dark-mode.css @@ -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'); +} \ No newline at end of file diff --git a/asset/dark-mode.js b/asset/dark-mode.js new file mode 100644 index 0000000000000000000000000000000000000000..471dcf8009c1f7442466e890cbd0f56ef632cfae --- /dev/null +++ b/asset/dark-mode.js @@ -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() + +}) + diff --git a/asset/moon.svg b/asset/moon.svg new file mode 100644 index 0000000000000000000000000000000000000000..bc0bf105fe1e26ea85f045179ed98578250f46c4 --- /dev/null +++ b/asset/moon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/asset/sun.svg b/asset/sun.svg new file mode 100644 index 0000000000000000000000000000000000000000..8fb9960c795b7e9cc5dc25f301fe31f7a4993b16 --- /dev/null +++ b/asset/sun.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/index.html b/index.html index b567e6c1aeb0713fc6b9e1605e5a5f046919c1d6..083bc82d117e1c91c7aaa57110c897898c02fb04 100644 --- a/index.html +++ b/index.html @@ -15,6 +15,9 @@ + + +
now loading...