/
databox.js
53 lines (45 loc) · 1.69 KB
/
databox.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
52
53
'use strict'
function Databox () {
this.databox = document.createElement('div')
this.databox.id = 'databox'
this.scrubber = document.createElement('div')
this.scrubber.id = 'scrubber'
this.data = document.createElement('div')
this.data.id = 'data'
this.databox.appendChild(this.scrubber)
this.databox.appendChild(this.data)
const months = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC',]
const today = new Date()
this.install = function (host) {
host.appendChild(this.databox)
}
this.start = function () {
this.update()
}
this.update = function () {
const years = database.stats.years
const fullHeight = years * 12 * monthHeight
const monthsTotal = Math.round(window.scrollY / monthHeight)
const date = new Date(today.getFullYear(), today.getMonth() - monthsTotal)
const year = date.getFullYear()
const month = date.getMonth()
const m = month < 9 ? `0${month + 1}` : month + 1
this.databox.style = window.scrollY < fullHeight - 12 * monthHeight ? `opacity : 1;` : `opacity: 0;`
this.data.innerHTML = `<h1>${year}-${m}</h1>`
// check years database for entries
if (database.years[year]) {
const months = database.years[year][month]
if (months) {
for (const c in database.settings.CATEGORIES) {
const category = months[c]
const color = database.settings.CATEGORIES[c].COLOR
this.data.innerHTML += `<h2 style="color:${color}">${database.settings.CATEGORIES[c].NAME}</h2>`
this.data.innerHTML += category ? `<p>${category.description.toUpperCase()}</p>` : '<p>---</p>'
}
}
}
}
window.addEventListener('scroll', function(e) {
chronicle.interface.databox.update()
})
}