-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuserscript.js
44 lines (34 loc) · 1.3 KB
/
userscript.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
(() => {
'use-strict'
const themeSwiter = {
init: function() {
this.wrapper = document.getElementById('theme-switcher-wrapper')
this.button = document.getElementById('theme-switcher-button')
this.theme = this.wrapper.querySelectorAll('[data-theme]')
this.themes = ['theme-orange', 'theme-purple', 'theme-green', 'theme-blue']
this.events()
this.start()
},
events: function() {
this.button.addEventListener('click', this.displayed.bind(this), false)
this.theme.forEach(theme => theme.addEventListener('click', this.themed.bind(this), false))
},
start: function() {
let theme = this.themes[Math.floor(Math.random() * this.themes.length)]
document.body.classList.add(theme)
},
displayed: function() {
(this.wrapper.classList.contains('is-open'))
? this.wrapper.classList.remove('is-open')
: this.wrapper.classList.add('is-open')
},
themed: function(e) {
this.themes.forEach(theme => {
if(document.body.classList.contains(theme))
document.body.classList.remove(theme)
})
return document.body.classList.add(`theme-${e.currentTarget.dataset.theme}`)
}
}
themeSwiter.init()
})()