<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>☆★ゲッダン★☆ タイピング速度計測</title>
  <style>
    body { font-family: Arial, sans-serif; text-align: center; margin-top: 50px; }
    input { font-size: 20px; padding: 10px; width: 50%; }
    .speed { font-size: 24px; margin-top: 20px; }
  </style>
</head>
<body>

  <h1>☆★ゲッダン★☆ タイピング速度測定</h1>
  <p>次の文字をできるだけ速く入力してください：</p>
  <p><strong>☆★ゲッダン★☆</strong></p>
  <input type="text" id="typingInput" placeholder="ここに入力..." />
  <div class="speed" id="speedDisplay"></div>

  <script>
    const targetText = "☆★ゲッダン★☆";
    const inputField = document.getElementById("typingInput");
    const speedDisplay = document.getElementById("speedDisplay");

    let startTime = null;
    let finished = false;

    inputField.addEventListener("input", () => {
      const inputText = inputField.value;

      // タイマー開始条件：1文字目が入力された瞬間
      if (startTime === null && inputText.length > 0) {
        startTime = Date.now();
      }

      // 入力完了でタイマー停止
      if (!finished && inputText === targetText) {
        const endTime = Date.now();
        const timeTaken = (endTime - startTime) / 1000;
        const speed = targetText.length / timeTaken;

        speedDisplay.innerHTML = `速度: ${speed.toFixed(15)} 文字/秒 (タイム: ${timeTaken.toFixed(15)}秒)`;
        finished = true;
      }
    });

    // 再挑戦用に入力欄リセットで初期化
    inputField.addEventListener("focus", () => {
      if (finished) {
        startTime = null;
        finished = false;
        speedDisplay.textContent = "";
        inputField.value = "";
      }
    });
  </script>

</body>
</html>