-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.51ef91ec09.js
61 lines (52 loc) · 1.88 KB
/
util.51ef91ec09.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
(function() {
function updateCheckboxUI(bool) {
const checkmarkContainer = document.getElementById('cm')
if (checkmarkContainer) {
checkmarkContainer.style.display = bool ? 'inline' : 'none'
}
}
function ensureLength(monthData) {
while (monthData.length <= 31) {
monthData.push(0)
}
return monthData
}
function readSavedMonth(month) {
const monthJson = localStorage.getItem(month)
return ensureLength(monthJson ? JSON.parse(monthJson) : [])
}
function writeSavedMonth(month, monthData) {
localStorage.setItem(month, JSON.stringify(ensureLength(monthData)))
}
function markMonthAs(month, complete){
var monthData = readSavedMonth(month)
writeSavedMonth(month, monthData.map(function(){ return complete ? 1 : 0 }))
}
function markDayAs(month, day, complete) {
const monthData = readSavedMonth(month)
monthData[day] = complete ? 1 : 0
writeSavedMonth(month, monthData)
updateCheckboxUI(monthData[day])
}
function initDayPage(month, day) {
const monthData = readSavedMonth(month)
updateCheckboxUI(monthData[day])
updateIsTodayUI(month, day)
setInterval(updateIsTodayUI, 1000, month, day)
}
function updateIsTodayUI(month, day) {
const eleMonthAndDay = document.getElementById('month-and-day')
eleMonthAndDay.classList[isRelativeDay(month, day, -1) ? 'add' : 'remove' ]('yesterday')
eleMonthAndDay.classList[isRelativeDay(month, day, 0) ? 'add' : 'remove' ]('today')
eleMonthAndDay.classList[isRelativeDay(month, day, 1) ? 'add' : 'remove' ]('tomorrow')
}
function isRelativeDay(month, day, offsetDays) {
const offsetDate = new Date()
offsetDate.setDate(offsetDate.getDate() + offsetDays)
const offsetDayString = offsetDate.toLocaleDateString('en-US', { month: 'numeric', day: 'numeric' })
return offsetDayString === month + '/' + day
}
window.markMonthAs = markMonthAs
window.markDayAs = markDayAs
window.initDayPage = initDayPage
})()