-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathorg-html-themify.js
51 lines (41 loc) · 1.22 KB
/
org-html-themify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
let cookie = document.cookie.split('; ').find(r => r.startsWith('org_html_themify_theme'))
let theme = 'light'
if (cookie) {
theme = cookie.split('=')[1]
}
let toggleThemeBtn = document.getElementById('toggle-theme')
let toggleTocBtn = document.getElementById('toggle-toc')
if (theme == 'light') {
useLightTheme();
} else {
useDarkTheme();
}
function transition() {
document.body.classList.add('theme-transition')
setTimeout(() => document.body.classList.remove('theme-transition'), 500)
}
function useLightTheme(theme) {
document.body.dataset.theme = 'light'
toggleThemeBtn.innerHTML = 'dark theme'
document.cookie = 'org_html_themify_theme=light'
}
function useDarkTheme(theme) {
document.body.dataset.theme = 'dark'
toggleThemeBtn.innerHTML = 'light theme'
document.cookie = 'org_html_themify_theme=dark'
}
toggleThemeBtn.addEventListener('click', function() {
transition()
if (document.body.dataset.theme == 'light') {
useDarkTheme();
} else {
useLightTheme();
}
})
let toc = document.getElementById('table-of-contents')
toggleTocBtn.addEventListener('click', function() {
toc.classList.add('toc-show')
toc.addEventListener('click', function() {
toc.classList.remove('toc-show')
})
})