-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaily-notes-dow.js
28 lines (20 loc) · 1.01 KB
/
daily-notes-dow.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
dailyLogDateObserver = new MutationObserver(addDow)
dailyLogDateObserver.observe(document, { childList: true, subtree: true });
function addDow() {
const dateRegex = /^([A-Z][a-z]+) (\d{1,2})(\w\w), (\d{4})$/;
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
const nodes = document.querySelectorAll('.roam-log-page > h1.rm-title-display');
for (let heading of nodes) {
const text = heading.textContent;
if (!dateRegex.test(text)) {
continue;
}
const [ _, month, day, daySuffix, year ] = dateRegex.exec(text);
const date = new Date(year, months.indexOf(month), day);
dailyLogDateObserver.disconnect()
const dowLong = date.toLocaleString(window.navigator.language, { weekday: 'long' });
heading.innerHTML = `${text} <span style="font-size: 0.5em; color: gray;">${dowLong}</span>`;
dailyLogDateObserver.observe(document, { childList: true, subtree: true });
}
}
setTimeout(addDow, 1000);