forked from bastianallgeier/bulletjournal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
65 lines (48 loc) · 1.5 KB
/
Copy pathapp.js
File metadata and controls
65 lines (48 loc) · 1.5 KB
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
const days = Array.from(document.querySelectorAll(".day"));
const notes = Array.from(document.querySelectorAll("textarea"));
document.addEventListener("keydown", (event) => {
if (event.metaKey && event.key.toLowerCase() === "s") {
event.preventDefault();
}
});
function highlightCurrentDay() {
if (document.visibilityState !== "visible") {
return;
}
const today = new Date();
days.forEach((day, index) => {
unhighlightDay(day);
if (index === today.getDay() - 1) {
const dateString = `${today.getDate()}.${today.getMonth() + 1}.`;
highlightDay(day, dateString);
}
});
}
function highlightDay(day, dateString) {
day.setAttribute("aria-current", "date");
const date = document.createElement("span");
date.textContent = dateString;
const note = day.querySelector("textarea");
const heading = day.querySelector(".heading");
note.setAttribute("autofocus", "true");
note.focus();
heading.append(date);
}
function unhighlightDay(day) {
day.removeAttribute("aria-current");
const note = day.querySelector("textarea");
const existingDate = day.querySelector(".heading > span");
note.removeAttribute("autofocus");
if (existingDate !== null) {
existingDate.remove();
}
}
highlightCurrentDay();
document.addEventListener("visibilitychange", highlightCurrentDay);
notes.forEach((note) => {
const { id } = note;
note.value = localStorage.getItem(id) ?? "";
note.addEventListener("input", () => {
localStorage.setItem(id, note.value);
});
});