-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
81 lines (75 loc) · 3.07 KB
/
script.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
let twoAClock = moment().set({
'hour': 14,
'minute': 0,
'second': 0,
'millisecond': 0
})
let dates = [
{
// Mondays
id: 'paper',
start: moment(twoAClock).day( moment(twoAClock).day() >= 1 ? 1 :-6 ),
stop: moment(twoAClock).day( moment(twoAClock).day() >= 1 ? 1 :-6 ).add(1,'w')
},
{
// Mondays and Thursday and Friday
id: 'well',
start: moment(twoAClock).day( moment(twoAClock).day() >= 5 ? 5 : moment(twoAClock).day() >= 4 ? 4 : moment(twoAClock).day() >= 1 ? 1 : -2 ),
stop: moment(twoAClock).day( moment(twoAClock).day() >= 5 ? 8 : moment(twoAClock).day() >= 4 ? 5 : moment(twoAClock).day() >= 1 ? 4 : 1 )
},
{
// Mondays, Tuesdays and Friday
id: 'plastic',
start: moment(twoAClock).day( moment(twoAClock).day() >= 5 ? 5 : moment(twoAClock).day() >= 2 ? 2 : moment(twoAClock).day() >= 1 ? 1 : -2 ),
stop: moment(twoAClock).day( moment(twoAClock).day() >= 5 ? 9 : moment(twoAClock).day() >= 2 ? 5 : moment(twoAClock).day() >= 1 ? 2 : 1 )
},
{
// Wednesday
id: 'bio',
start: moment(twoAClock).day( moment(twoAClock).day() >= 3 ? 3 :-4 ),
stop: moment(twoAClock).day( moment(twoAClock).day() >= 3 ? 3 :-4 ).add(1,'w')
},
{
// Wednesdays
id: 'glas',
start: moment(twoAClock).day( moment(twoAClock).day() >= 3 ? 3 :-4 ),
stop: moment(twoAClock).day( moment(twoAClock).day() >= 3 ? 3 :-4 ).add(1, 'w')
},
{
// Fridays even weeks
id: 'metal',
start: moment(twoAClock).day( moment().isoWeek() % 2 ? -2 : moment(twoAClock).day() >= 5 ? 5 : -9 ),
stop: moment(twoAClock).day( moment().isoWeek() % 2 ? -2 : moment(twoAClock).day() >= 5 ? 5 : -9 ).add(2, 'w')
},
{
// Tuesdays and Friday
id: 'household',
start: moment(twoAClock).day( moment(twoAClock).day() >= 5 ? 5 : moment(twoAClock).day() >= 2 ? 2 : -2 ),
stop: moment(twoAClock).day( moment(twoAClock).day() >= 5 ? 9 : moment(twoAClock).day() >= 2 ? 5 : 2 )
}
]
getCurrentPos = function(start, stop, value) {
let distance = stop - start
let normValue = value - start
return normValue / distance
}
const firstLoad = moment().valueOf();
let updateValues = function() {
document.querySelector('.lastUpdate').innerHTML = moment().valueOf() - firstLoad
dates.forEach((bin, i) => {
let val = getCurrentPos( +bin.start, +bin.stop, +moment() )
if (val < 0) {
document.querySelector(`#${bin.id} .bin-fill`).style.width = '100%'
document.querySelector(`#${bin.id} .answer`).innerHTML = 'vänta'
document.querySelector(`#${bin.id} .next`).innerHTML = 'senare idag'
document.querySelector(`#${bin.id} .next`).title = 'Senare idag'
} else {
document.querySelector(`#${bin.id} .bin-fill`).style.width = val * 100 + '%'
document.querySelector(`#${bin.id} .answer`).innerHTML = val < 0.3 ? 'ja' : val < 0.8 ? 'kanske' : 'vänta'
document.querySelector(`#${bin.id} .next`).innerHTML = bin.stop.fromNow()
document.querySelector(`#${bin.id} .next`).title = bin.stop.format('[På] dddd')
}
});
}
document.addEventListener("visibilitychange", updateValues, false);
updateValues()