static/js/common.js (view raw)
1document.addEventListener('DOMContentLoaded', function () {
2 const navObject = document.getElementsByTagName("nav")[0];
3 for (const page of navPages) {
4 const a = document.createElement("a");
5 a.innerText = page.name;
6 a.href = page.href;
7 navObject.appendChild(a)
8 }
9});
10
11const navPages = [
12 { name: "Home", href: "/" },
13 { name: "Bookmakers", href: "/bookmakers" },
14 { name: "Accounts", href: "/accounts" },
15 { name: "Records", href: "/records" },
16];
17
18const currency = "€";
19const locale = "it-IT";
20
21function formatValue(v) {
22 return (v / 100).toFixed(2);
23}
24
25function formatCash(v) {
26 return formatValue(v) + currency;
27}
28
29function formatDate(dateString) {
30 return (new Date(dateString)).toLocaleString(locale);
31}
32
33function fixDate(date) {
34 date.toISOString().split('T')[0]
35}
36
37async function myFetch(url) {
38 res = await fetch(url);
39 if (!res.ok) {
40 console.error(res.text())
41 return
42 }
43
44 return await res.json();
45}
46
47async function getRecords() {
48 return await myFetch('/api/records');
49}