hibiscus/pages/index.html
2024-03-18 00:51:27 +03:00

95 lines
No EOL
2.8 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="/public/css/main.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hibiscus.txt</title>
</head>
<body>
<header>
<h1 style="margin-bottom:0;margin-top:0;">🌺 Hibiscus.txt</h1>
<p id="status" style="margin-top:0;">Today is <span id="today-date">14/03/2024</span></p>
</header>
<main>
<h2 style="margin-bottom:0;"><label for="day">Your day so far:</label></h2>
<textarea id="day" name="Day entry" cols="40" rows="10" style="max-width: 640px; width: 100%"></textarea>
<div class="grid"><button onclick="saveToday()">Save</button></div>
<h2><label for="log">Log</label></h2>
<input type="text" id="log" name="log" style="max-width: 640px; width: 100%"/>
<div class="grid"><button onclick="saveLog()">Send</button></div>
</main>
</body>
<script defer>
function updateTime() {
let todayDate = new Date()
let timeField = document.getElementById("today-date")
timeField.innerText = todayDate.toISOString().split('T')[0]
}
updateTime()
async function postData(url = "", data = "") {
const response = await fetch(url, {
method: "POST",
credentials: "same-origin",
headers: {
"Content-Type": "text/plain",
},
redirect: "follow",
referrerPolicy: "no-referrer",
body: data,
});
if (response.ok) {
return response.text();
} else {
return response.status
}
}
async function getData(url = "", data = "") {
const response = await fetch(url, {
method: "GET",
credentials: "same-origin",
redirect: "follow",
referrerPolicy: "no-referrer"
});
if (response.ok) {
return response.text();
} else {
console.log(response.text())
return response.status
// return "Error"
}
}
function saveLog() {
let logField = document.getElementById("log")
postData("/api/log", logField.value).then((data) => {
if (data !== 500) {
logField.value = ""
}
});
}
function saveToday() {
let logField = document.getElementById("day")
postData("/api/today", logField.value).then((data) => {
console.log(data);
});
}
function loadToday() {
let dayField = document.getElementById("day")
getData("/api/today", dayField.value).then((data) => {
if (data !== 404) {
dayField.value = data
} else {
dayField.value = ""
}
});
}
loadToday()
</script>
</html>