ツール管理へ戻るv2 のソース
<!doctype html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>回答待ち時間の記録</title>
<style>
:root {
font-family: system-ui, -apple-system, "Noto Sans JP", sans-serif;
color: #1f2937;
background: #f3f6fa;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 32px 16px;
}
main {
max-width: 760px;
margin: 0 auto;
padding: 28px;
background: #fff;
border: 1px solid #dce3ec;
border-radius: 14px;
box-shadow: 0 8px 24px rgba(31, 41, 55, 0.07);
}
h1 {
margin: 0 0 8px;
font-size: 1.6rem;
}
.description {
margin: 0 0 24px;
color: #526174;
line-height: 1.6;
}
.field {
margin-bottom: 18px;
}
.field label,
fieldset legend {
display: block;
margin-bottom: 7px;
font-weight: 700;
}
.example {
margin: 5px 0 0;
color: #64748b;
font-size: 0.9rem;
}
input[type="number"],
input[type="text"],
textarea {
width: 100%;
padding: 10px 12px;
border: 1px solid #bcc8d6;
border-radius: 7px;
font: inherit;
background: #fff;
}
input:focus,
textarea:focus {
outline: 3px solid rgba(37, 99, 235, 0.18);
border-color: #2563eb;
}
textarea {
min-height: 82px;
resize: vertical;
}
.minutes-row {
display: flex;
align-items: center;
gap: 10px;
}
.minutes-row input {
max-width: 180px;
}
fieldset {
margin: 0 0 18px;
padding: 14px;
border: 1px solid #dce3ec;
border-radius: 9px;
}
fieldset legend {
padding: 0 5px;
}
.choice {
display: inline-flex;
align-items: center;
gap: 7px;
margin: 3px 18px 3px 0;
cursor: pointer;
}
.choice input {
margin: 0;
}
.error {
display: none;
margin: 0 0 16px;
padding: 11px 13px;
color: #9b1c1c;
background: #fff1f1;
border: 1px solid #f0b8b8;
border-radius: 7px;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-top: 22px;
}
button {
padding: 10px 15px;
border: 0;
border-radius: 7px;
font: inherit;
font-weight: 700;
cursor: pointer;
}
button:hover {
filter: brightness(0.96);
}
.primary {
color: #fff;
background: #2563eb;
}
.secondary {
color: #263548;
background: #e8edf3;
}
.result {
display: none;
margin-top: 24px;
padding: 16px;
border: 1px solid #b9dec4;
border-radius: 9px;
background: #f2fbf4;
}
.result h2 {
margin: 0 0 8px;
font-size: 1.1rem;
}
.result p {
margin: 0;
line-height: 1.6;
}
.notice {
margin-top: 18px;
color: #64748b;
font-size: 0.9rem;
line-height: 1.5;
}
@media (max-width: 520px) {
body {
padding: 16px 10px;
}
main {
padding: 20px 16px;
}
}
</style>
</head>
<body>
<main>
<h1>回答待ち時間の記録</h1>
<p class="description">
入力した内容を、Excelで開けるCSVファイルとしてダウンロードできます。
</p>
<form id="recordForm" novalidate>
<div class="field">
<label for="waitMinutes">待ち時間(分)</label>
<div class="minutes-row">
<input
id="waitMinutes"
name="waitMinutes"
type="number"
min="0"
step="1"
placeholder="例:60"
inputmode="numeric"
required
>
<span>分</span>
</div>
<p class="example">入力例:60(約1時間)</p>
</div>
<div class="field">
<label for="counterparty">相手の区分</label>
<input
id="counterparty"
name="counterparty"
type="text"
placeholder="例:お客様、部下"
required
>
<p class="example">個人名などは入力しないでください。</p>
</div>
<div class="field">
<label for="request">依頼内容</label>
<textarea
id="request"
name="request"
placeholder="例:部品の納期確認"
required
></textarea>
</div>
<fieldset>
<legend>作業状況</legend>
<label class="choice">
<input type="radio" name="workStatus" value="作業が止まった">
作業が止まった
</label>
<label class="choice">
<input type="radio" name="workStatus" value="別の仕事をしていた">
別の仕事をしていた
</label>
<label class="choice">
<input type="radio" name="workStatus" value="影響なし">
影響なし
</label>
<p class="example">いずれかを選択してください。</p>
</fieldset>
<div class="field">
<label for="impact">影響</label>
<textarea
id="impact"
name="impact"
placeholder="例:次工程の開始が遅れた"
required
></textarea>
</div>
<p class="error" id="errorMessage" role="alert"></p>
<div class="actions">
<button class="primary" type="submit">CSVをダウンロード</button>
<button class="secondary" type="reset">入力を初期化</button>
</div>
</form>
<section class="result" id="resultMessage" aria-live="polite">
<h2>CSVを作成しました</h2>
<p>入力した5項目を1行にまとめたCSVファイルをダウンロードしました。</p>
</section>
<p class="notice">
このページはブラウザ内だけで動作し、入力内容の保存や外部への送信は行いません。
ダウンロードしたCSVファイルは、お使いのパソコンで適切に管理してください。
</p>
</main>
<script>
"use strict";
const form = document.getElementById("recordForm");
const errorMessage = document.getElementById("errorMessage");
const resultMessage = document.getElementById("resultMessage");
function getFormData() {
const selectedStatus = form.querySelector('input[name="workStatus"]:checked');
return {
waitMinutes: document.getElementById("waitMinutes").value.trim(),
counterparty: document.getElementById("counterparty").value.trim(),
request: document.getElementById("request").value.trim(),
workStatus: selectedStatus ? selectedStatus.value : "",
impact: document.getElementById("impact").value.trim()
};
}
function validateData(data) {
const minutes = Number(data.waitMinutes);
if (data.waitMinutes === "") {
return "待ち時間を入力してください。";
}
if (!Number.isFinite(minutes) || !Number.isInteger(minutes) || minutes < 0) {
return "待ち時間は0以上の整数で入力してください。";
}
if (!data.counterparty) {
return "相手の区分を入力してください。";
}
if (!data.request) {
return "依頼内容を入力してください。";
}
if (!data.workStatus) {
return "作業状況を選択してください。";
}
if (!data.impact) {
return "影響を入力してください。";
}
return "";
}
function escapeCsvCell(value) {
let safeValue = String(value);
// Excelで開いた際に、数式として解釈される可能性のある文字を無効化する
if (/^[\s]*[=+\-@]/.test(safeValue)) {
safeValue = "'" + safeValue;
}
return '"' + safeValue.replace(/"/g, '""') + '"';
}
function createCsv(data) {
const headers = [
"待ち時間(分)",
"相手の区分",
"依頼内容",
"作業状況",
"影響"
];
const values = [
data.waitMinutes,
data.counterparty,
data.request,
data.workStatus,
data.impact
];
return [
headers.map(escapeCsvCell).join(","),
values.map(escapeCsvCell).join(",")
].join("\r\n");
}
function downloadCsv(csvText) {
const bom = "\uFEFF";
const blob = new Blob([bom, csvText], {
type: "text/csv;charset=utf-8"
});
const downloadUrl = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = downloadUrl;
link.download = "回答待ち時間の記録.csv";
document.body.appendChild(link);
link.click();
link.remove();
window.setTimeout(function () {
URL.revokeObjectURL(downloadUrl);
}, 1000);
}
function showError(message) {
errorMessage.textContent = message;
errorMessage.style.display = "block";
resultMessage.style.display = "none";
}
function clearMessages() {
errorMessage.textContent = "";
errorMessage.style.display = "none";
resultMessage.style.display = "none";
}
form.addEventListener("submit", function (event) {
event.preventDefault();
clearMessages();
const data = getFormData();
const validationError = validateData(data);
if (validationError) {
showError(validationError);
return;
}
const csvText = createCsv(data);
downloadCsv(csvText);
resultMessage.style.display = "block";
});
form.addEventListener("reset", function () {
window.setTimeout(clearMessages, 0);
});
</script>
</body>
</html>