-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
593 lines (559 loc) · 25.9 KB
/
Copy pathindex.html
File metadata and controls
593 lines (559 loc) · 25.9 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>休日・休診日 +4週/+8週 ハイライト</title>
<link rel="icon" type="image/png" sizes="1254x1254" href="./favicon.png">
<link rel="apple-touch-icon" href="./favicon.png">
<link rel="manifest" href="./manifest.webmanifest">
<meta name="theme-color" content="#ffffff">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<!-- FullCalendar -->
<script src="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.11/index.global.min.js"></script>
<style>
body { font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", Meiryo, sans-serif; margin: 16px; }
.display-controls { max-width:1100px; margin:0 auto 12px; padding:10px 12px; box-sizing:border-box; display:flex; gap:8px; flex-wrap:wrap; align-items:center; border:1px solid #ddd; border-radius:10px; background:#f7f7f7; }
.display-controls label { display:inline-flex; gap:6px; align-items:center; padding:5px 9px; border:1px solid #ddd; border-radius:999px; background:#fff; white-space:nowrap; }
.display-controls #reload { margin-left:auto; }
#calendar { max-width: 1100px; margin: 0 auto; touch-action:manipulation; }
.note { max-width: 1100px; margin: 10px auto 0; color:#555; font-size: 13px; }
.pill { display:inline-block; padding:2px 8px; border-radius:999px; margin-right:6px; font-size:12px; }
.p-h { background:#ffebe9; border:1px solid #ffb4ad; }
.p-c { background:#fff1dc; border:1px solid #efb763; }
.p-4 { background:#e8f0fe; border:1px solid #a8c7fa; }
.p-8 { background:#e6f4ea; border:1px solid #a8dab5; }
.p-m { background:#f0e7ff; border:1px solid #c6a8e8; }
.closure-panel { max-width:1100px; margin:0 auto 12px; box-sizing:border-box; border:1px solid #ddd; border-radius:10px; overflow:hidden; }
.closure-panel summary { padding:11px 14px; cursor:pointer; font-weight:600; background:#f7f7f7; }
.closure-panel[open] summary { border-bottom:1px solid #ddd; }
.closure-panel-body { padding:12px 14px; }
.closure-actions { display:flex; gap:8px; flex-wrap:wrap; align-items:center; }
.closure-panel p { margin:6px 0 0; font-size:13px; color:#555; }
button, input[type="date"] { font:inherit; padding:6px 10px; }
button { cursor:pointer; }
button:disabled { cursor:default; }
#storageStatus, #holidayStatus, #memoStatus, #memoStorageStatus { color:#a12b21; }
.fc .closure-selected { box-shadow:inset 0 0 0 2px #986621; }
#memoDialog { width:min(560px, calc(100% - 32px)); max-height:calc(100dvh - 32px); padding:20px; box-sizing:border-box; border:1px solid #ddd; border-radius:12px; overflow:auto; }
#memoDialog::backdrop { background:rgb(0 0 0 / 35%); }
#memoDialog h2 { margin:0 0 16px; font-size:1.25em; }
#memoDialog label { display:block; margin-bottom:6px; }
#memoText { width:100%; min-height:180px; box-sizing:border-box; padding:10px; font:inherit; font-size:16px; line-height:1.6; resize:vertical; }
#memoDialog p { font-size:13px; color:#555; }
#memoDialog #memoStatus { color:#a12b21; }
.memo-actions { display:grid; grid-template-columns:minmax(0, 1fr) auto auto; gap:10px; margin-top:16px; }
#exportObsidian { justify-self:start; }
@media (max-width:600px) {
body { margin:8px; }
.display-controls { padding:8px; }
.display-controls #reload { margin-left:0; }
.closure-actions { display:grid; grid-template-columns:1fr 1fr; }
#closureDate, #openMemo { grid-column:1 / -1; width:100%; box-sizing:border-box; }
#setClosure, #removeClosure, #openMemo { width:100%; }
.fc .fc-header-toolbar { flex-wrap:wrap; gap:8px; }
.fc .fc-toolbar-title { font-size:1.25em; }
.memo-actions { grid-template-columns:1fr 1fr; }
#exportObsidian { grid-column:1 / -1; justify-self:stretch; width:100%; }
#cancelMemo, #saveMemo { width:100%; }
}
</style>
</head>
<body>
<div class="display-controls" aria-label="表示項目">
<label><input id="toggleHoliday" type="checkbox" checked>祝日</label>
<label><input id="toggleClosure" type="checkbox" checked>休診日</label>
<label><input id="togglePlus4" type="checkbox" checked>4週間後(+28日)</label>
<label><input id="togglePlus8" type="checkbox" checked>8週間後(+56日)</label>
<button id="reload">再読み込み</button>
</div>
<details class="closure-panel">
<summary>休診日にする日付</summary>
<form id="closureForm" class="closure-panel-body">
<div class="closure-actions">
<input id="closureDate" type="date" min="0100-01-01" max="9998-12-31" required aria-label="休診日にする日付" aria-describedby="closureHelp closureStatus">
<button id="setClosure" type="submit">休診に設定</button>
<button id="removeClosure" type="button" disabled>休診を解除</button>
<button id="openMemo" type="button">この日のメモ</button>
</div>
<p id="closureHelp">日付を選んで「休診に設定」を押してください。カレンダーの日付や「休診」ラベルをクリックしても選択できます。</p>
<p>休診日と、その4週後・8週後を表示します。設定はこの端末・ブラウザー内に保存されます。別の端末とは共有されず、ブラウザーのデータを消去すると設定も消えます。</p>
<p id="closureStatus" role="status"></p>
<p id="storageStatus" role="alert"></p>
</form>
</details>
<div class="note">
<span class="pill p-h">祝日</span>
<span class="pill p-c">休診</span>
<span class="pill p-4">+4週</span>
<span class="pill p-8">+8週</span>
<span class="pill p-m">メモあり</span>
<div id="memoStorageStatus" role="alert"></div>
<div id="memoNotice" role="status"></div>
<div style="margin-top:6px;">
祝日データは Holidays JP API(JSON)から取得します。取得に失敗したら、ネット接続を確認してください。
</div>
<div id="holidayStatus" role="status"></div>
</div>
<div id="calendar"></div>
<dialog id="memoDialog" aria-labelledby="memoDate" aria-describedby="memoHelp memoExportHelp">
<form id="memoForm">
<h2 id="memoDate"></h2>
<label for="memoText">外来診療メモ</label>
<textarea id="memoText" rows="8" placeholder="その日の申し送りや気づいたことなど" autofocus></textarea>
<p id="memoHelp">メモはこの端末・ブラウザー内に保存されます。空欄で保存すると、この日のメモを削除します。</p>
<p id="memoExportHelp">「Obsidianへ送る」は、現在入力中の内容から新しいMarkdownノートを作ります。Obsidianで最後に使用した保管庫が開きます。</p>
<p id="memoStatus" role="alert"></p>
<div class="memo-actions">
<button id="exportObsidian" type="button">Obsidianへ送る</button>
<button id="cancelMemo" type="button">キャンセル</button>
<button id="saveMemo" type="submit">保存</button>
</div>
</form>
</dialog>
<script>
// ---- 設定 ----
const HOLIDAY_API = "https://holidays-jp.github.io/api/v1/date.json";
const CLOSED_DATES_KEY = "holiday-plus-weeks-closed-dates-v1";
const MEMOS_KEY = "holiday-plus-weeks-memos-v1";
const TZ = "Asia/Tokyo";
// ---- 日付ユーティリティ ----
const pad2 = (n) => String(n).padStart(2, "0");
const toYMD = (d) => `${String(d.getFullYear()).padStart(4, "0")}-${pad2(d.getMonth()+1)}-${pad2(d.getDate())}`;
const parseYMD = (ymd) => {
const [y, m, dd] = ymd.split("-").map(Number);
return new Date(y, m - 1, dd);
};
const addDays = (date, days) => {
const d = new Date(date.getTime());
d.setDate(d.getDate() + days);
return d;
};
const isValidClosureDate = (ymd) => typeof ymd === "string"
&& /^\d{4}-\d{2}-\d{2}$/.test(ymd)
&& ymd >= "0100-01-01" && ymd <= "9998-12-31"
&& toYMD(parseYMD(ymd)) === ymd;
let calendar;
let holidayMap = {};
let closureDates = new Set();
let storageAvailable = true;
let memos = {};
let memoStorageAvailable = true;
let activeMemoDate = null;
let originalMemoText = "";
let lastDateTap = null;
let selectedDayEl = null;
const closureDateInput = document.getElementById("closureDate");
const memoDialog = document.getElementById("memoDialog");
const memoTextInput = document.getElementById("memoText");
// ---- 日付ごとのメモ ----
function readMemos() {
const stored = localStorage.getItem(MEMOS_KEY);
const data = stored === null ? {} : JSON.parse(stored);
if (!data || typeof data !== "object" || Array.isArray(data)
|| !Object.entries(data).every(([ymd, text]) => isValidClosureDate(ymd) && typeof text === "string")) {
throw new Error("Invalid memo data");
}
return data;
}
function loadMemos() {
try {
const data = readMemos();
memoStorageAvailable = true;
document.getElementById("memoStorageStatus").textContent = "";
return data;
} catch (err) {
memoStorageAvailable = false;
document.getElementById("memoStorageStatus").textContent =
"保存したメモを読み込めません。既存のメモを保護するため保存を停止しています。ブラウザーの保存設定を確認してください。";
return memos;
}
}
function saveMemo(ymd, text, expectedText) {
if (!memoStorageAvailable || !isValidClosureDate(ymd) || typeof text !== "string") return false;
try {
// 別タブで変更された他の日のメモを消さないよう、保存直前に読み直す。
const next = readMemos();
if (expectedText !== undefined && (next[ymd] || "") !== expectedText) {
document.getElementById("memoStatus").textContent =
"この日のメモは別の画面で変更されています。入力内容を控えてから、メモを開き直してください。入力内容はまだ保存していません。";
return false;
}
if (text.trim()) next[ymd] = text;
else delete next[ymd];
localStorage.setItem(MEMOS_KEY, JSON.stringify(next));
memos = next;
} catch (err) {
document.getElementById("memoStatus").textContent =
"メモを保存できませんでした。入力内容はこの画面に残っています。ブラウザーの保存設定や空き容量を確認して、もう一度保存してください。";
return false;
}
document.getElementById("memoStatus").textContent = "";
document.getElementById("memoStorageStatus").textContent = "";
document.getElementById("memoNotice").textContent =
`${ymd} のメモを${text.trim() ? "保存" : "削除"}しました。`;
refreshEvents();
return true;
}
function buildObsidianExportUri(ymd, text) {
if (!isValidClosureDate(ymd) || typeof text !== "string" || !text.trim()) return null;
const title = `${ymd} 外来診療メモ`;
const markdown = [
"---",
`date: ${ymd}`,
"source: 外来予約カレンダー",
"---",
"",
`# ${title}`,
"",
text,
""
].join("\n");
// overwrite/append を付けず、Obsidian側の既存ノートを変更しない。
return `obsidian://new?name=${encodeURIComponent(title)}&content=${encodeURIComponent(markdown)}&paneType=tab`;
}
function exportMemoToObsidian(ymd, text) {
const uri = buildObsidianExportUri(ymd, text);
if (!uri) {
document.getElementById("memoStatus").textContent =
"Obsidianへ送る内容を入力してください。";
return false;
}
document.getElementById("memoStatus").textContent = "Obsidianを開いています…";
window.location.href = uri;
return true;
}
function openMemo(ymd) {
if (!isValidClosureDate(ymd) || memoDialog.open) return;
lastDateTap = null;
memos = loadMemos();
activeMemoDate = ymd;
originalMemoText = memos[ymd] || "";
document.getElementById("memoDate").textContent = `${ymd} のメモ`;
memoTextInput.value = originalMemoText;
document.getElementById("saveMemo").disabled = !memoStorageAvailable;
document.getElementById("memoStatus").textContent = memoStorageAvailable ? ""
: "メモを読み込めないため保存を停止しています。ブラウザーの保存設定を確認してください。";
memoDialog.showModal();
memoTextInput.focus();
}
function closeMemo() {
memoDialog.close();
activeMemoDate = null;
lastDateTap = null;
}
function handleDateClick(info) {
const ymd = info.dateStr;
const time = info.jsEvent?.timeStamp ?? Date.now();
if (lastDateTap && lastDateTap.date === ymd
&& time - lastDateTap.time >= 0 && time - lastDateTap.time <= 450) {
openMemo(ymd);
return;
}
lastDateTap = { date: ymd, time };
// 2回目のタップ前に FullCalendar を再描画しない。
closureDateInput.value = ymd;
updateClosureControls();
if (selectedDayEl) selectedDayEl.classList.remove("closure-selected");
selectedDayEl = info.dayEl || null;
if (selectedDayEl) selectedDayEl.classList.add("closure-selected");
}
function buildMemoEvents(notes) {
return Object.entries(notes).filter(([, text]) => text.trim()).map(([ymd]) => ({
title: "メモあり",
start: ymd,
allDay: true,
backgroundColor: "#f0e7ff",
borderColor: "#c6a8e8",
textColor: "#000",
extendedProps: { kind: "memo", base: ymd }
}));
}
// ---- 休診日の保存 ----
function loadClosedDates() {
try {
const stored = localStorage.getItem(CLOSED_DATES_KEY);
const dates = stored === null ? [] : JSON.parse(stored);
if (!Array.isArray(dates) || !dates.every(isValidClosureDate)) {
throw new Error("Invalid closure dates");
}
storageAvailable = true;
document.getElementById("storageStatus").textContent = "";
return new Set(dates);
} catch (err) {
// 読めない既存データを空の設定で上書きしない。
storageAvailable = false;
document.getElementById("storageStatus").textContent =
"休診日の保存データを読み込めません。既存の設定を保護するため、設定・解除を停止しています。ブラウザーの保存設定を確認してください。";
return closureDates;
}
}
function saveClosure(ymd, isClosed) {
if (!storageAvailable || !isValidClosureDate(ymd)) return false;
const next = new Set(closureDates);
if (isClosed) next.add(ymd);
else next.delete(ymd);
try {
localStorage.setItem(CLOSED_DATES_KEY, JSON.stringify([...next].sort()));
} catch (err) {
document.getElementById("storageStatus").textContent =
"休診日を保存できませんでした。変更は反映していません。ブラウザーの保存設定や空き容量を確認してください。";
return false;
}
closureDates = next;
document.getElementById("storageStatus").textContent = "";
refreshEvents();
updateClosureControls();
document.getElementById("closureStatus").textContent =
`${ymd} の休診${isClosed ? "を設定しました。" : "を解除しました。祝日・年末年始の表示は残ります。"}`;
return true;
}
// ---- 祝日取得 ----
async function fetchHolidays() {
const res = await fetch(HOLIDAY_API, { cache: "no-store" });
if (!res.ok) throw new Error("祝日API取得失敗: " + res.status);
return await res.json();
}
// ---- イベント生成 ----
function buildEvents(holidays, opts, closedDates = []) {
const events = [];
const closureSet = new Set(closedDates);
const holidayDates = { ...holidays };
const now = new Date();
const from = new Date(now.getFullYear() - 1, 0, 1);
const to = new Date(now.getFullYear() + 2, 11, 31);
// 年末年始(12/28〜1/3)はこれまでどおり毎年休日にする。
for (let y = from.getFullYear(); y <= to.getFullYear(); y++) {
for (let d = 28; d <= 31; d++) {
const ymd = `${y}-12-${pad2(d)}`;
if (!holidayDates[ymd]) holidayDates[ymd] = "年末年始";
}
for (let d = 1; d <= 3; d++) {
const ymd = `${y}-01-${pad2(d)}`;
if (!holidayDates[ymd]) holidayDates[ymd] = "年末年始";
}
}
const baseDates = new Set(Object.keys(holidayDates).filter((ymd) => {
const date = parseYMD(ymd);
return date >= from && date <= to;
}));
// 手動設定した休診日は、上記の年の範囲にかかわらず表示する。
for (const ymd of closureSet) baseDates.add(ymd);
for (const ymd of [...baseDates].sort()) {
const date = parseYMD(ymd);
const holidayName = holidayDates[ymd];
const isClosed = closureSet.has(ymd);
const sourceName = isClosed
? (holidayName ? `休診・${holidayName}` : "休診")
: holidayName;
const showClosure = isClosed && opts.showClosure;
const showHoliday = holidayName && opts.showHoliday;
if (showClosure || showHoliday) {
const kind = showClosure ? "closure" : "holiday";
events.push({
title: showClosure ? "休診" : holidayName,
start: ymd,
allDay: true,
display: "background",
backgroundColor: showClosure ? "#fff1dc" : "#ffebe9",
extendedProps: { kind, base: ymd }
});
}
if (showHoliday) {
events.push({
title: "祝日: " + holidayName,
start: ymd,
allDay: true,
backgroundColor: "#ffb4ad",
borderColor: "#ffb4ad",
textColor: "#000",
extendedProps: { kind: "holiday_label", base: ymd }
});
}
if (showClosure) {
events.push({
title: "休診",
start: ymd,
allDay: true,
backgroundColor: "#efb763",
borderColor: "#efb763",
textColor: "#000",
extendedProps: { kind: "closure_label", base: ymd }
});
}
// 同じ日が祝日と休診日の両方でも、各週のイベントは1つにまとめる。
for (const [weeks, show, color] of [
[4, opts.showPlus4, "#a8c7fa"],
[8, opts.showPlus8, "#a8dab5"]
]) {
if (!show) continue;
events.push({
title: `+${weeks}週 (${sourceName})`,
start: toYMD(addDays(date, weeks * 7)),
allDay: true,
backgroundColor: color,
borderColor: color,
textColor: "#000",
extendedProps: { kind: `plus${weeks}`, base: ymd, sourceName }
});
}
}
return events;
}
// ---- 表示更新(表示中の月・週を保つ) ----
function refreshEvents() {
if (!calendar) return;
const events = buildEvents(holidayMap, {
showHoliday: document.getElementById("toggleHoliday").checked,
showClosure: document.getElementById("toggleClosure").checked,
showPlus4: document.getElementById("togglePlus4").checked,
showPlus8: document.getElementById("togglePlus8").checked
}, closureDates);
events.push(...buildMemoEvents(memos));
calendar.batchRendering(() => {
calendar.getEventSources().forEach((source) => source.remove());
calendar.addEventSource(events);
});
}
function updateClosureControls() {
const ymd = closureDateInput.value;
const valid = isValidClosureDate(ymd);
const isClosed = closureDates.has(ymd);
document.getElementById("openMemo").disabled = !valid;
document.getElementById("setClosure").disabled = !storageAvailable || !valid || isClosed;
document.getElementById("removeClosure").disabled = !storageAvailable || !valid || !isClosed;
document.getElementById("closureStatus").textContent = valid
? `${ymd}: ${isClosed ? "休診に設定されています。" : "手動の休診設定はありません。"}`
: "有効な日付を選んでください。";
}
function selectClosureDate(ymd, { navigate = true } = {}) {
closureDateInput.value = ymd;
updateClosureControls();
if (calendar && isValidClosureDate(ymd)) {
if (navigate) calendar.gotoDate(ymd);
// FullCalendar の名前付きタイムゾーン(プラグインなし)は UTC の日付を使う。
calendar.setOption("dayCellClassNames", (info) =>
info.date.toISOString().slice(0, 10) === ymd ? ["closure-selected"] : []);
}
}
async function reloadHolidays() {
const button = document.getElementById("reload");
button.disabled = true;
document.getElementById("holidayStatus").textContent = "祝日データを読み込み中…";
try {
holidayMap = await fetchHolidays();
document.getElementById("holidayStatus").textContent = "";
refreshEvents();
} catch (err) {
document.getElementById("holidayStatus").textContent =
"祝日データを取得できませんでした。ネット接続を確認して再読み込みしてください。休診日の設定・表示は引き続き利用できます。";
} finally {
button.disabled = false;
}
}
// ---- カレンダー初期化 ----
closureDates = loadClosedDates();
memos = loadMemos();
closureDateInput.value = toYMD(new Date());
calendar = new FullCalendar.Calendar(document.getElementById("calendar"), {
timeZone: TZ,
initialView: "dayGridMonth",
locale: "ja",
height: "auto",
firstDay: 1,
headerToolbar: {
left: "prev,next today",
center: "title",
right: "dayGridMonth,dayGridWeek,listMonth"
},
dateClick: handleDateClick,
datesSet: () => {
lastDateTap = null;
selectedDayEl = null;
},
eventClick: (info) => {
lastDateTap = null;
const p = info.event.extendedProps || {};
if (p.kind === "memo") {
openMemo(p.base);
} else if (p.kind === "closure_label") {
selectClosureDate(p.base);
document.getElementById("removeClosure").focus();
} else if (p.kind === "plus4" || p.kind === "plus8") {
alert(`${info.event.title}\n元の休日・休診日: ${p.sourceName}\n元の日付: ${p.base}\nこの日付: ${info.event.startStr}`);
} else if (p.kind === "holiday_label") {
selectClosureDate(p.base);
alert(`${info.event.title}\n日付: ${info.event.startStr}`);
}
}
});
calendar.render();
refreshEvents();
selectClosureDate(closureDateInput.value);
// ---- UI ----
document.getElementById("openMemo").addEventListener("click", () => openMemo(closureDateInput.value));
document.getElementById("exportObsidian").addEventListener("click", () => {
exportMemoToObsidian(activeMemoDate, memoTextInput.value);
});
document.getElementById("memoForm").addEventListener("submit", (event) => {
event.preventDefault();
if (saveMemo(activeMemoDate, memoTextInput.value, originalMemoText)) closeMemo();
});
document.getElementById("cancelMemo").addEventListener("click", closeMemo);
memoDialog.addEventListener("cancel", (event) => {
event.preventDefault();
if (memoTextInput.value !== originalMemoText) {
document.getElementById("memoStatus").textContent =
"未保存の入力があります。「保存」するか、「キャンセル」で入力を破棄してください。";
} else {
closeMemo();
}
});
document.getElementById("closureForm").addEventListener("submit", (event) => {
event.preventDefault();
if (saveClosure(closureDateInput.value, true)) calendar.gotoDate(closureDateInput.value);
});
document.getElementById("removeClosure").addEventListener("click", () => {
saveClosure(closureDateInput.value, false);
});
closureDateInput.addEventListener("change", () => selectClosureDate(closureDateInput.value));
document.getElementById("reload").addEventListener("click", reloadHolidays);
for (const id of ["toggleHoliday", "toggleClosure", "togglePlus4", "togglePlus8"]) {
document.getElementById(id).addEventListener("change", refreshEvents);
}
// 同じブラウザーの別タブで変更した場合も追従する。
window.addEventListener("storage", (event) => {
if (event.key === CLOSED_DATES_KEY || event.key === null) {
closureDates = loadClosedDates();
updateClosureControls();
}
if (event.key === MEMOS_KEY || event.key === null) {
memos = loadMemos();
document.getElementById("saveMemo").disabled = !memoStorageAvailable;
// 編集中の本文は書き換えず、保存時に同日の変更を確認する。
if (memoDialog.open && !memoStorageAvailable) {
document.getElementById("memoStatus").textContent =
"保存データを読み込めなくなりました。入力内容はこの画面に残っています。";
}
}
if ([CLOSED_DATES_KEY, MEMOS_KEY, null].includes(event.key)) refreshEvents();
});
reloadHolidays();
</script>
<script>
if ("serviceWorker" in navigator) {
window.addEventListener("load", async () => {
try {
await navigator.serviceWorker.register("./sw.js", {
scope: "./",
updateViaCache: "none"
});
} catch (e) {
console.warn("Service Worker registration failed:", e);
}
});
}
</script>
</body>
</html>