Refactor everything
This commit is contained in:
parent
b56ce43c80
commit
57903d4724
45 changed files with 514 additions and 416 deletions
50
internal/server/public/main.js
Normal file
50
internal/server/public/main.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
// Format time in "Jan 02, 2006" format
|
||||
function formatDate(date) {
|
||||
let options = {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric'
|
||||
}
|
||||
if (timeZone !== "Local") { options.timeZone = timeZone }
|
||||
let dateFormat = new Intl.DateTimeFormat([langName, "en"], options)
|
||||
return dateFormat.format(date)
|
||||
}
|
||||
|
||||
async function graceActive() {
|
||||
const response = await fetch("/api/grace");
|
||||
const active = await response.text();
|
||||
return active === "true"
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// Start interval to update time at start of every minute
|
||||
function callEveryMinute() {
|
||||
setInterval(updateTime, 1000 * 60);
|
||||
}
|
||||
|
||||
// Begin above interval
|
||||
function beginTimeUpdater() {
|
||||
const difference = (60 - new Date().getSeconds()) * 1000;
|
||||
setTimeout(callEveryMinute, difference);
|
||||
setTimeout(updateTime, difference);
|
||||
updateTime();
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue