-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
167 lines (156 loc) · 4.26 KB
/
Copy pathindex.html
File metadata and controls
167 lines (156 loc) · 4.26 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE html><html lang="ja"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width">
<title>鯖江市営駐車場満車・空車状況</title>
</head><body>
<!--
<h1>鯖江市営駐車場満車・空車状況</h1>
-->
<main id=main>
<div id=lastUpdate></div>
<div id=table></div>
<!--
※空き情報の更新タイミングには時間差がございます。名称を選択すると地図が表示されます。
-->
</main>
<!--
<hr>
<footer>
駐車場リアルタイムオープンデータ提供: CC BY <a href=https://www.city.sabae.fukui.jp/>鯖江市役所</a>
(<a href=https://data.city.sabae.lg.jp/opendata-list/>データシティ鯖江 オープンデータ一覧</a>)
</footer>
-->
<script type="module">
import { getParking, updateParking } from "./parking.js";
import { DateTime } from "https://js.sabae.cc/DateTime.js";
//import { setAutoTransposeTable } from "./transposeTable.js";
import { transposeTable } from "./transposeTable.js";
const parking = await getParking();
const cr = (tag, p) => {
const res = document.createElement(tag);
p.appendChild(res);
return res;
};
const tbl = cr("table", table);
const tr = cr("tr", tbl);
for (const name of ["名称", "満空状況", "収容台数", "住所", "利用料金"]) {
const th = cr("th", tr);
tr.appendChild(th, tr);
th.textContent = name;
}
let id = 1;
const lastp = {};
for (const p of parking) {
const tr = cr("tr", tbl);
const omitname = ["open", "price"];
for (const name of ["name", null, "capacity", "address", "price"]) { // "open"
if (!name) {
const td = cr("td", tr);
td.id = "fig" + id++;
} else {
const s = p[name].replace(/。/g, "。\n") + (name == "capacity" ? "台" : "");
if (lastp[name]?.name == p[name]) {
const rs = lastp[name].td.getAttribute("rowspan") || 1;
lastp[name].td.setAttribute("rowspan", rs + 1);
} else {
const td = cr("td", tr);
if (false) { // name == "name" || name == "address") {
const a = cr("a", td);
a.target = "_blank";
//a.href = `https://www.google.com/maps/dir/?api=1&destination=${p.lat},${p.lng}`;
a.href = `https://maps.google.com/?ll=${p.lat},${p.lng}`;
//a.href = `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(p.name)}`;
a.textContent = s;
} else {
td.textContent = s;
}
td.className = name;
if (omitname.indexOf(name) >= 0) {
lastp[name] = { name: p[name], td };
}
}
}
}
}
//setAutoTransposeTable(tbl, 600);
transposeTable(tbl);
const update = async () => {
await updateParking(parking);
for (let i = 0; i < parking.length; i++) {
const flg = parking[i].full;
const fig = document.getElementById("fig" + (i + 1));
const child = document.createElement("span");
child.textContent = flg ? "満車" : "空車";
fig.appendChild(child);
fig.className = flg ? "full" : "space";
if ( fig.getElementsByTagName("span").length > 1 ) {
const rm_child = fig.getElementsByTagName("span")[0];
fig.removeChild(rm_child);
}
}
const d = new DateTime();
lastUpdate.textContent = `${d.day.year}年${d.day.month}月${d.day.day}日 ${d.time.hour}時${d.time.min}分 現在`;
};
update();
setInterval(update, 60 * 1000); // 1min
</script>
<style>
body {
text-align: center;
font-family: sans-serif;
margin: 0;
}
h1 {
margin: 0 0 .2em 0;
padding: .5em;
background-color: #77aa77;
color: white;
font-size: 5vw;
}
main {
text-align: left;
max-width: 90vw;
display: inline-block;
margin: 1em;
}
table {
display: inline-block;
border-collapse: collapse;
border: 1px solid black;
}
td, th {
border: 1px solid black;
padding: .2em .8em;
}
th {
background-color: #ddd;
text-align: center;
font-weight: normal;
}
.name, .capacity, .full, .space, .address, .open {
text-align: center;
}
.price {
white-space: pre-wrap;
}
.full, .space{
color: white;
font-weight: bolder;
font-size:2em;
letter-spacing: 0.1em;
white-space: nowrap;
}
.full span{
background-color: red;
padding: 0.05em 0.3em 0.05em 0.4em;
}
.space span{
background-color: blue;
padding: 0.05em 0.3em 0.05em 0.4em;
}
footer a {
color: gray !important;
}
a {
color: #333 !important;
}
</style>
</body></html>