2024-03-28 10:42:52 +03:00
|
|
|
// Format time in "Jan 02, 2006" format
|
2024-03-27 11:51:33 +03:00
|
|
|
function formatDate(date) {
|
2024-05-10 01:27:20 +03:00
|
|
|
let options = {
|
2024-03-27 11:51:33 +03:00
|
|
|
year: 'numeric',
|
|
|
|
month: 'short',
|
2024-05-10 01:27:20 +03:00
|
|
|
day: 'numeric'
|
|
|
|
}
|
|
|
|
if (timeZone !== "Local") { options.timeZone = timeZone }
|
|
|
|
let dateFormat = new Intl.DateTimeFormat([langName, "en"], options)
|
2024-05-05 13:06:20 +03:00
|
|
|
return dateFormat.format(date)
|
2024-03-27 11:51:33 +03:00
|
|
|
}
|
|
|
|
|
2024-05-06 14:53:18 +03:00
|
|
|
async function graceActive() {
|
|
|
|
const response = await fetch("/api/grace");
|
|
|
|
const active = await response.text();
|
|
|
|
return active === "true"
|
|
|
|
}
|
2024-03-18 15:01:09 +03:00
|
|
|
|
2024-05-06 14:53:18 +03:00
|
|
|
// Set today's date and grace status
|
|
|
|
function updateTime() {
|
|
|
|
document.getElementById("today-date").innerText = formatDate(Date.now());
|
|
|
|
graceActive().then(v => document.getElementById("grace").hidden = !v)
|
2024-03-18 15:01:09 +03:00
|
|
|
}
|
|
|
|
|
2024-05-06 14:53:18 +03:00
|
|
|
// Start interval to update time at start of every minute
|
|
|
|
function callEveryMinute() {
|
|
|
|
setInterval(updateTime, 1000 * 60);
|
2024-03-18 15:01:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Begin above interval
|
2024-05-06 14:53:18 +03:00
|
|
|
function beginTimeUpdater() {
|
|
|
|
const difference = (60 - new Date().getSeconds()) * 1000;
|
|
|
|
setTimeout(callEveryMinute, difference);
|
|
|
|
setTimeout(updateTime, difference);
|
|
|
|
updateTime();
|
2024-05-08 16:49:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// This does NOT properly sanitize, and assumes a well-meaning user
|
|
|
|
function sanitize(title) {
|
|
|
|
return title
|
|
|
|
.trim()
|
|
|
|
.replace(/ +/g, '-')
|
|
|
|
.replace(/[!*'();:@&=+$,\/?#\[\]]/g, '')
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open a new note
|
|
|
|
function newNote(text_prompt) {
|
|
|
|
name = sanitize(prompt(text_prompt + ':'))
|
|
|
|
window.location.replace('/notes/' + name)
|
2024-03-18 15:01:09 +03:00
|
|
|
}
|