Skip to content
C
31.5 KB
Raw Blame
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="theme-color" content="#07111f">
    <link rel="icon" type="image/png" sizes="64x64" href="fav.png?v=3">
    <link rel="shortcut icon" type="image/png" href="fav.png?v=3">
    <link rel="apple-touch-icon" href="fav.png?v=3">
    <meta name="description" content="Install the ESP32 GT7 Dashboard firmware from a compatible browser.">
    <meta property="og:type" content="website">
    <meta property="og:title" content="ESP32 GT7 Dashboard Installer">
    <meta property="og:description" content="Install the ESP32 GT7 Dashboard with six switchable GT7 telemetry themes.">
    <meta property="og:url" content="https://caa1211.github.io/esp32-gt7-dashboard/">
    <meta property="og:image" content="https://caa1211.github.io/esp32-gt7-dashboard/og-image.jpg?v=2">
    <meta property="og:image:width" content="1200">
    <meta property="og:image:height" content="630">
    <meta property="og:image:alt" content="Classic, GT3, Retro, Radar, Mono and Pocket ESP32 GT7 Dashboard themes">
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:title" content="ESP32 GT7 Dashboard Installer">
    <meta name="twitter:description" content="Install the ESP32 GT7 Dashboard with six switchable GT7 telemetry themes.">
    <meta name="twitter:image" content="https://caa1211.github.io/esp32-gt7-dashboard/og-image.jpg?v=2">
    <title>ESP32 GT7 Dashboard Installer</title>
    <script type="module" src="https://unpkg.com/esp-web-tools@10/dist/web/install-button.js?module"></script>
    <style>
      :root {
        color-scheme: dark;
        font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
        background: #07111f;
        color: #e7eef8;
      }

      * { box-sizing: border-box; }

      body {
        min-height: 100vh;
        margin: 0;
        display: grid;
        place-items: center;
        padding: 24px;
        background:
          radial-gradient(circle at top left, rgba(14, 165, 233, 0.24), transparent 42%),
          radial-gradient(circle at bottom right, rgba(37, 99, 235, 0.20), transparent 38%),
          #07111f;
      }

      .corner-profile {
        flex: 0 0 clamp(96px, 12vw, 125px);
        text-align: center;
      }

      .title-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 24px;
      }

      .title-copy { min-width: 0; }

      .corner-image {
        display: block;
        width: 100%;
        aspect-ratio: 1;
        border: 1px solid rgba(148, 163, 184, 0.28);
        border-radius: 18px;
        object-fit: cover;
        box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
      }

      .facebook-link {
        display: inline-block;
        margin-top: 8px;
        color: #8fa3bb;
        font-size: 0.78rem;
        font-weight: 500;
        text-decoration: underline;
        text-decoration-color: rgba(143, 163, 187, 0.35);
        text-underline-offset: 3px;
      }

      .facebook-link:hover {
        color: #b7c5d8;
        text-decoration-color: currentColor;
      }

      @media (max-width: 600px) {
        .corner-profile {
          flex-basis: 82px;
        }

        .corner-image {
          border-radius: 14px;
        }

      }

      main {
        position: relative;
        width: min(100%, 800px);
        padding: clamp(28px, 6vw, 52px);
        border: 1px solid rgba(148, 163, 184, 0.22);
        border-radius: 24px;
        background: rgba(15, 23, 42, 0.88);
        box-shadow: 0 28px 80px rgba(0, 0, 0, 0.35);
        backdrop-filter: blur(14px);
      }

      .language-toggle {
        position: absolute;
        top: 18px;
        right: 20px;
        padding: 6px 11px;
        border: 1px solid rgba(148, 163, 184, 0.32);
        border-radius: 999px;
        background: rgba(148, 163, 184, 0.08);
        color: #cbd5e1;
        cursor: pointer;
        font: inherit;
        font-size: 0.78rem;
        font-weight: 700;
      }

      .language-toggle:hover { background: rgba(148, 163, 184, 0.16); }

      .eyebrow {
        margin: 0 0 10px;
        color: #38bdf8;
        font-size: 0.82rem;
        font-weight: 750;
        letter-spacing: 0.14em;
        text-transform: uppercase;
      }

      .release-version {
        display: inline-flex;
        align-items: center;
        gap: 7px;
        padding: 6px 10px;
        border: 1px solid rgba(56, 189, 248, 0.28);
        border-radius: 999px;
        background: rgba(14, 165, 233, 0.1);
        color: #bae6fd;
        cursor: pointer;
        font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
        font-size: 0.85rem;
      }

      .release-version:hover { background: rgba(14, 165, 233, 0.18); }

      .version-chevron { font-size: 0.7rem; }

      .version-icon {
        width: 14px;
        height: 14px;
        flex: 0 0 auto;
        fill: none;
        stroke: currentColor;
        stroke-linecap: round;
        stroke-linejoin: round;
        stroke-width: 1.8;
      }

      .version-actions {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px;
        margin-top: 16px;
      }

      .kofi-button {
        display: inline-flex;
        align-items: center;
        padding: 6px 11px;
        border: 1px solid rgba(253, 164, 175, 0.4);
        border-radius: 999px;
        background: rgba(244, 63, 94, 0.14);
        color: #fecdd3;
        font-size: 0.85rem;
        font-weight: 700;
        text-decoration: none;
      }

      .kofi-button:hover {
        background: rgba(244, 63, 94, 0.24);
        color: #fff1f2;
      }

      .share-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 52px;
        min-height: 32px;
        padding: 6px;
        border: 1px solid rgba(148, 163, 184, 0.32);
        border-radius: 999px;
        background: rgba(148, 163, 184, 0.08);
        color: #cbd5e1;
        cursor: pointer;
        font: inherit;
        font-size: 0.85rem;
        font-weight: 700;
      }

      .share-button:hover { background: rgba(148, 163, 184, 0.16); }

      .share-button.copied { color: #86efac; }
      .share-button.failed { color: #fda4af; }

      .share-icon {
        width: 17px;
        height: 17px;
        transform: translateX(-2px);
        fill: none;
        stroke: currentColor;
        stroke-linecap: round;
        stroke-linejoin: round;
        stroke-width: 1.8;
      }

      .theme-preview {
        margin: 24px 0 0;
        overflow: hidden;
        border: 1px solid rgba(148, 163, 184, 0.24);
        border-radius: 16px;
        background: #000;
        box-shadow: 0 16px 36px rgba(0, 0, 0, 0.28);
      }

      .theme-preview img {
        display: block;
        width: 100%;
        height: auto;
      }

      .theme-preview figcaption {
        padding: 10px 14px;
        border-top: 1px solid rgba(148, 163, 184, 0.18);
        color: #94a3b8;
        font-size: 0.8rem;
        text-align: center;
      }

      h1 {
        margin: 0;
        font-size: clamp(2rem, 7vw, 3.7rem);
        line-height: 1.02;
        letter-spacing: -0.045em;
      }

      .lead {
        margin: 20px 0 0;
        color: #b7c5d8;
        font-size: 1.05rem;
        line-height: 1.7;
      }

      .steps {
        margin: 30px 0;
        padding: 22px 22px 22px 44px;
        border-radius: 16px;
        background: rgba(30, 41, 59, 0.72);
        color: #d8e2ef;
        line-height: 1.75;
      }

      .compatibility-warning {
        margin: 0 0 10px;
        color: #fbbf24;
        font-size: 0.85rem;
        line-height: 1.6;
        text-align: center;
      }

      .install {
        display: flex;
        justify-content: center;
        padding: 8px 0 16px;
      }

      .simhub-protocol-link {
        display: block;
        width: fit-content;
        margin: -4px auto 14px;
        color: #7dd3fc;
        font-size: 0.88rem;
        font-weight: 700;
        text-align: center;
        text-decoration: none;
      }

      .simhub-protocol-link:hover {
        color: #bae6fd;
        text-decoration: underline;
      }

      .firmware-choice {
        margin: 0 auto 14px;
        max-width: 360px;
      }

      .firmware-choice label {
        display: block;
        margin-bottom: 7px;
        color: #d8e2ef;
        font-size: 0.9rem;
        font-weight: 700;
        text-align: center;
      }

      .firmware-choice select {
        width: 100%;
        padding: 11px 36px 11px 13px;
        border: 1px solid rgba(56, 189, 248, 0.35);
        border-radius: 10px;
        background: #172033;
        color: #f8fafc;
        font: inherit;
      }

      .firmware-choice p {
        margin: 7px 0 0;
        color: #8fa3bb;
        font-size: 0.78rem;
        line-height: 1.45;
        text-align: center;
      }

      .version-dialog {
        width: min(calc(100% - 32px), 460px);
        padding: 0;
        border: 1px solid rgba(148, 163, 184, 0.28);
        border-radius: 18px;
        background: #111c2c;
        color: #e7eef8;
        box-shadow: 0 28px 80px rgba(0, 0, 0, 0.55);
      }

      .version-dialog::backdrop { background: rgba(2, 6, 23, 0.72); }

      .version-dialog-content { padding: 22px; }

      .version-dialog-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
      }

      .version-dialog h2 { margin: 0; font-size: 1.15rem; }

      .version-dialog-close {
        border: 0;
        background: transparent;
        color: #94a3b8;
        cursor: pointer;
        font-size: 1.35rem;
      }

      .version-list { display: grid; gap: 9px; margin-top: 18px; }

      .version-option {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        width: 100%;
        padding: 12px 14px;
        border: 1px solid rgba(148, 163, 184, 0.22);
        border-radius: 10px;
        background: #172033;
        color: #e7eef8;
        cursor: pointer;
        font: inherit;
        text-align: left;
      }

      .version-option:hover { border-color: rgba(56, 189, 248, 0.5); }

      .version-option[aria-current="true"] {
        border-color: #38bdf8;
        background: rgba(14, 165, 233, 0.13);
      }

      .version-option small { color: #7dd3fc; }

      .version-notes {
        margin: 14px 0 0;
        padding-left: 20px;
        color: #b7c5d8;
        font-size: 0.85rem;
        line-height: 1.55;
      }

      .version-dialog-confirm {
        width: 100%;
        margin-top: 18px;
        padding: 11px 16px;
        border: 0;
        border-radius: 10px;
        background: #0ea5e9;
        color: #fff;
        cursor: pointer;
        font: inherit;
        font-weight: 750;
      }

      .version-dialog-confirm:hover { background: #38bdf8; }

      .connect-button {
        width: 280px;
        max-width: 100%;
        padding: 16px 28px;
        border: 0;
        border-radius: 12px;
        background: #0ea5e9;
        color: #fff;
        cursor: pointer;
        font: inherit;
        font-size: 1.12rem;
        font-weight: 750;
        box-shadow: 0 12px 28px rgba(14, 165, 233, 0.28);
      }

      .connect-button:hover { background: #38bdf8; }

      .connect-button:focus-visible {
        outline: 3px solid rgba(125, 211, 252, 0.65);
        outline-offset: 3px;
      }

      .quick-start {
        margin-top: 28px;
        padding: 22px;
        border: 1px solid rgba(34, 197, 94, 0.3);
        border-radius: 16px;
        background: rgba(20, 83, 45, 0.2);
      }

      .quick-start h2 {
        margin: 0;
        color: #86efac;
        font-size: 1.15rem;
      }

      .quick-start p {
        margin: 14px 0 8px;
        color: #d8e2ef;
        font-weight: 650;
      }

      .quick-start ol {
        margin: 0;
        padding-left: 24px;
        color: #b7c5d8;
        line-height: 1.75;
      }

      .wifi-name {
        display: inline-block;
        margin-top: 4px;
        padding: 2px 8px;
        border-radius: 6px;
        background: rgba(15, 23, 42, 0.8);
        color: #f8fafc;
        font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
        font-weight: 700;
      }

      .project-support {
        margin-top: 28px;
        padding: 22px;
        border: 1px solid rgba(250, 204, 21, 0.3);
        border-radius: 16px;
        background: rgba(113, 63, 18, 0.18);
        text-align: center;
      }

      .project-support h2 {
        margin: 0 0 12px;
        color: #fde68a;
        font-size: 1.15rem;
      }

      .project-support p {
        margin: 8px 0;
        color: #d8e2ef;
        line-height: 1.6;
      }

      .star-link {
        display: inline-block;
        margin: 10px 0 4px;
        padding: 10px 16px;
        border-radius: 10px;
        background: #facc15;
        color: #422006;
        font-weight: 750;
        text-decoration: none;
      }

      .star-link:hover {
        background: #fde047;
        color: #422006;
      }

      a { color: #7dd3fc; }
      a:hover { color: #bae6fd; }

      footer {
        margin-top: 28px;
        padding-top: 22px;
        border-top: 1px solid rgba(148, 163, 184, 0.18);
        color: #8fa3bb;
        font-size: 0.88rem;
        text-align: center;
      }
    </style>
  </head>
  <body>
    <main>
      <button class="language-toggle" id="language-toggle" type="button">中文</button>
      <p class="eyebrow" data-i18n="eyebrow">USB Web Installer</p>
      <div class="title-row">
        <div class="title-copy">
          <h1>ESP32 GT7 Dashboard</h1>
          <div class="version-actions">
            <button
              class="release-version"
              id="version-menu-button"
              type="button"
              aria-haspopup="dialog"
              aria-live="polite"
            >
              <svg class="version-icon" viewBox="0 0 24 24" aria-hidden="true">
                <path d="M20 13 11 22l-9-9V4h9l9 9Z"></path>
                <circle cx="7" cy="9" r="1.5"></circle>
              </svg>
              <span id="release-version">Version loading…</span>
              <span class="version-chevron" aria-hidden="true">▼</span>
            </button>
            <a
              class="kofi-button"
              href="https://ko-fi.com/caa1211"
              target="_blank"
              rel="noopener noreferrer"
            >☕ Support me on Ko-fi</a>
            <button class="share-button" id="share-button" type="button" aria-label="Share installer" title="Share installer">
              <svg class="share-icon" viewBox="0 0 24 24" aria-hidden="true">
                <circle cx="18" cy="5" r="3"></circle>
                <circle cx="6" cy="12" r="3"></circle>
                <circle cx="18" cy="19" r="3"></circle>
                <path d="m8.6 10.5 6.8-4M8.6 13.5l6.8 4"></path>
              </svg>
            </button>
          </div>
        </div>
        <aside class="corner-profile" aria-label="Project creator">
          <img class="corner-image" src="image.png" alt="ESP32 GT7 Dashboard project photo">
          <a
            class="facebook-link"
            href="https://www.facebook.com/caa1211"
            target="_blank"
            rel="noopener noreferrer"
          >facebook: caa1211</a>
        </aside>
      </div>
      <p class="lead" data-i18n="lead">
        Install the dashboard firmware directly from a compatible desktop browser.
        No additional software or tools are required.
      </p>

      <ol class="steps" id="install-steps">
        <li>Connect the classic ESP32 board with a data-capable USB cable.</li>
        <li>Close serial monitors and other programs using its serial port.</li>
        <li>Select <strong>Install firmware</strong>, choose the port, and confirm.</li>
        <li>Leave the board connected until the installation finishes.</li>
      </ol>

      <div class="firmware-choice">
        <label for="display-controller" id="controller-label">Display controller</label>
        <select id="display-controller">
          <option value="ili9341">ILI9341 (standard)</option>
          <option value="st7789">ST7789 (alternate)</option>
        </select>
        <p id="controller-help">Select the controller fitted to your ESP32-2432S028.</p>
      </div>

      <div class="install">
        <esp-web-install-button id="install-button" manifest="manifest.json">
          <button class="connect-button" id="connect-button" slot="activate">Connect &amp; install</button>
          <button id="unsupported-button" slot="unsupported">Use Chrome, Edge, or another Web Serial browser</button>
        </esp-web-install-button>
      </div>

      <a
        class="simhub-protocol-link"
        id="simhub-guide-link"
        href="https://github.com/caa1211/esp32-gt7-dashboard/blob/main/SIMHUB_README.md"
        target="_blank"
        rel="noopener noreferrer"
      >Using SimHub? View setup guide ↗</a>
      <a
        class="simhub-protocol-link"
        id="simhub-protocol-link"
        href="https://raw.githubusercontent.com/caa1211/esp32-gt7-dashboard/main/simhub/custom-protocol.txt"
        target="_blank"
        rel="noopener noreferrer"
      >Open Custom Protocol ↗</a>

      <p class="compatibility-warning" id="compatibility-warning">
        ⚠️ ESP32-2432S028 only. Installing replaces the firmware currently on the device.
      </p>

      <figure class="theme-preview">
        <img src="theme_all.jpg?v=2" alt="ESP32 GT7 Dashboard theme collection">
        <figcaption id="theme-caption">Six switchable themes. The same live GT7 telemetry in every layout.</figcaption>
      </figure>

      <section class="quick-start" id="quick-start" aria-labelledby="quick-start-title">
        <h2 id="quick-start-title">✅ Installation complete</h2>
        <p>Next steps:</p>
        <ol>
          <li>Disconnect USB.</li>
          <li>Reconnect power.</li>
          <li>Connect to Wi-Fi: <span class="wifi-name">GT7-DASH-SETUP</span></li>
        </ol>
      </section>

      <section class="project-support" id="project-support" aria-labelledby="project-support-title">
        <h2 id="project-support-title">❤️ Enjoying ESP32 GT7 Dashboard?</h2>
        <p>If this project helped you build your GT7 dashboard:</p>
        <a
          class="star-link"
          href="https://github.com/caa1211/esp32-gt7-dashboard"
          target="_blank"
          rel="noopener noreferrer"
        >⭐ Star this repository</a>
        <p>📢 Share it with other GT7 and sim racing enthusiasts.</p>
        <p>Every star and share helps the project reach more people.</p>
      </section>

      <footer id="page-footer">
        Firmware source and release instructions are available in the
        <a href="https://github.com/caa1211/esp32-gt7-dashboard">GitHub repository</a>.
      </footer>
    </main>

    <dialog class="version-dialog" id="version-dialog">
      <div class="version-dialog-content">
        <div class="version-dialog-header">
          <h2>Select firmware version</h2>
          <button class="version-dialog-close" id="version-dialog-close" type="button" aria-label="Close">×</button>
        </div>
        <div class="version-list" id="version-list"></div>
        <ul class="version-notes" id="version-notes"></ul>
        <button class="version-dialog-confirm" id="version-dialog-confirm" type="button">Use selected version</button>
      </div>
    </dialog>

    <script>
      const controllerSelect = document.getElementById("display-controller");
      const installButton = document.getElementById("install-button");
      const versionLabel = document.getElementById("release-version");
      const versionMenuButton = document.getElementById("version-menu-button");
      const versionDialog = document.getElementById("version-dialog");
      const versionDialogClose = document.getElementById("version-dialog-close");
      const versionDialogConfirm = document.getElementById("version-dialog-confirm");
      const versionList = document.getElementById("version-list");
      const versionNotes = document.getElementById("version-notes");
      const shareButton = document.getElementById("share-button");
      const languageToggle = document.getElementById("language-toggle");
      let releases = [];
      let selectedVersion = "";
      let previewVersion = "";
      let currentLanguage = "en";

      const translations = {
        en: {
          toggle: "中文",
          eyebrow: "USB Web Installer",
          lead: "Install the dashboard firmware directly from a compatible desktop browser. No additional software or tools are required.",
          steps: [
            "Connect the classic ESP32 board with a data-capable USB cable.",
            "Close serial monitors and other programs using its serial port.",
            "Select Install firmware, choose the port, and confirm.",
            "Leave the board connected until the installation finishes."
          ],
          controller: "Display controller",
          controllerHelp: "Select the controller fitted to your ESP32-2432S028.",
          connect: "Connect & install",
          unsupported: "Use Chrome, Edge, or another Web Serial browser",
          simhubGuide: "Using SimHub? View setup guide ↗",
          simhubProtocol: "Open Custom Protocol ↗",
          warning: "⚠️ ESP32-2432S028 only. Installing replaces the firmware currently on the device.",
          caption: "Six switchable themes. The same live GT7 telemetry in every layout.",
          complete: "✅ Installation complete",
          next: "Next steps:",
          quickSteps: ["Disconnect USB.", "Reconnect power."],
          wifi: "Connect to Wi-Fi:",
          enjoying: "🏁 Enjoying ESP32 GT7 Dashboard?",
          helped: "If this project helped you build your GT7 dashboard:",
          star: "⭐ Star this repository",
          shareProject: "📣 Share it with other GT7 and sim racing enthusiasts.",
          impact: "Every star and share helps the project reach more people.",
          footer: "Firmware source and release instructions are available in the",
          repository: "GitHub repository",
          selectVersion: "Select firmware version",
          latest: "Latest",
          useVersion: "Use Version",
          unavailable: "Version unavailable",
          share: "Share installer",
          copied: "Link copied",
          copyFailed: "Copy failed"
        },
        zh: {
          toggle: "EN",
          eyebrow: "USB 網頁安裝程式",
          lead: "使用相容的桌面瀏覽器即可直接安裝 Dashboard 韌體,不需要另外安裝任何軟體或工具。",
          steps: [
            "使用可傳輸資料的 USB 線連接 ESP32 開發板。",
            "關閉序列監控程式,以及其他正在使用該序列埠的程式。",
            "點選安裝韌體、選擇正確的連接埠,然後確認安裝。",
            "安裝完成前,請保持開發板連線。"
          ],
          controller: "顯示控制器",
          controllerHelp: "請選擇你的 ESP32-2432S028 所使用的顯示控制器。",
          connect: "連接並安裝",
          unsupported: "請使用 Chrome、Edge 或其他支援 Web Serial 的瀏覽器",
          simhubGuide: "使用 SimHub?查看設定教學 ↗",
          simhubProtocol: "開啟 Custom Protocol ↗",
          warning: "⚠️ 僅適用於 ESP32-2432S028。安裝後會取代裝置目前的韌體。",
          caption: "六種可切換主題,每種版面都顯示相同的即時 GT7 遙測資料。",
          complete: "✅ 安裝完成",
          next: "接下來:",
          quickSteps: ["拔除 USB。", "重新接上電源。"],
          wifi: "連接 Wi-Fi:",
          enjoying: "🏁 喜歡 ESP32 GT7 Dashboard 嗎?",
          helped: "如果這個專案幫助你完成 GT7 Dashboard:",
          star: "⭐ 幫這個專案加星",
          shareProject: "📣 分享給其他 GT7 與賽車模擬玩家。",
          impact: "每一個星星與分享,都能讓更多人看見這個專案。",
          footer: "韌體原始碼與發行說明可在此查看:",
          repository: "GitHub 專案頁面",
          selectVersion: "選擇韌體版本",
          latest: "最新",
          useVersion: "使用版本",
          unavailable: "無法取得版本資訊",
          share: "分享安裝程式",
          copied: "連結已複製",
          copyFailed: "複製失敗"
        }
      };

      function setLanguage(language) {
        currentLanguage = language;
        const text = translations[language];
        document.documentElement.lang = language === "zh" ? "zh-TW" : "en";
        languageToggle.textContent = text.toggle;
        document.querySelector(".eyebrow").textContent = text.eyebrow;
        document.querySelector(".lead").textContent = text.lead;
        document.querySelectorAll("#install-steps li").forEach((item, index) => item.textContent = text.steps[index]);
        document.getElementById("controller-label").textContent = text.controller;
        document.getElementById("controller-help").textContent = text.controllerHelp;
        document.getElementById("connect-button").textContent = text.connect;
        document.getElementById("unsupported-button").textContent = text.unsupported;
        document.getElementById("simhub-protocol-link").textContent = text.simhubProtocol;
        const simhubGuide = document.getElementById("simhub-guide-link");
        simhubGuide.textContent = text.simhubGuide;
        simhubGuide.href = `https://github.com/caa1211/esp32-gt7-dashboard/blob/main/SIMHUB_README${language === "zh" ? ".zh-TW" : ""}.md`;
        document.getElementById("compatibility-warning").textContent = text.warning;
        document.getElementById("theme-caption").textContent = text.caption;

        const quickStart = document.getElementById("quick-start");
        quickStart.querySelector("h2").textContent = text.complete;
        quickStart.querySelector("p").textContent = text.next;
        const quickItems = quickStart.querySelectorAll("li");
        quickItems[0].textContent = text.quickSteps[0];
        quickItems[1].textContent = text.quickSteps[1];
        quickItems[2].firstChild.textContent = `${text.wifi} `;

        const support = document.getElementById("project-support");
        support.querySelector("h2").textContent = text.enjoying;
        const supportParagraphs = support.querySelectorAll("p");
        supportParagraphs[0].textContent = text.helped;
        support.querySelector(".star-link").textContent = text.star;
        supportParagraphs[1].textContent = text.shareProject;
        supportParagraphs[2].textContent = text.impact;

        const footer = document.getElementById("page-footer");
        footer.firstChild.textContent = `${text.footer} `;
        footer.querySelector("a").textContent = text.repository;
        versionDialog.querySelector("h2").textContent = text.selectVersion;
        shareButton.title = text.share;
        shareButton.setAttribute("aria-label", text.share);
        selectManifest();
        if (versionDialog.open) renderVersionDialog();
      }

      languageToggle.addEventListener("click", () => {
        const nextLanguage = currentLanguage === "en" ? "zh" : "en";
        const url = new URL(window.location.href);
        url.searchParams.set("lang", nextLanguage === "zh" ? "zh-TW" : "en");
        window.history.replaceState({}, "", url);
        setLanguage(nextLanguage);
      });

      const requestedLanguage = new URLSearchParams(window.location.search).get("lang")?.toLowerCase();
      setLanguage(requestedLanguage === "zh" || requestedLanguage === "zh-tw" ? "zh" : "en");

      shareButton.addEventListener("click", async () => {
        const shareData = {
          title: "ESP32 GT7 Dashboard Installer",
          text: "Install the ESP32 GT7 Dashboard with six switchable telemetry themes.",
          url: window.location.href,
        };

        try {
          if (navigator.share) {
            await navigator.share(shareData);
            return;
          }
          await navigator.clipboard.writeText(shareData.url);
          shareButton.classList.add("copied");
          shareButton.title = translations[currentLanguage].copied;
          window.setTimeout(() => {
            shareButton.classList.remove("copied");
            shareButton.title = translations[currentLanguage].share;
          }, 1800);
        } catch (error) {
          if (error?.name === "AbortError") return;
          shareButton.classList.add("failed");
          shareButton.title = translations[currentLanguage].copyFailed;
          window.setTimeout(() => {
            shareButton.classList.remove("failed");
            shareButton.title = translations[currentLanguage].share;
          }, 1800);
        }
      });

      function selectedRelease() {
        return releases.find((release) => release.version === selectedVersion);
      }

      function selectManifest() {
        const release = selectedRelease();
        if (!release) return;

        const manifestPath = release.manifests[controllerSelect.value];
        installButton.setAttribute("manifest", manifestPath);
        versionLabel.textContent = `${currentLanguage === "zh" ? "版本" : "Version"} ${release.version}`;

      }

      function renderVersionDialog() {
        const release = releases.find((item) => item.version === previewVersion);
        if (!release) return;

        versionList.replaceChildren();
        releases.forEach((item, index) => {
          const option = document.createElement("button");
          option.type = "button";
          option.className = "version-option";
          option.dataset.version = item.version;
          option.setAttribute("aria-current", String(item.version === previewVersion));
          const label = document.createElement("span");
          label.textContent = `${currentLanguage === "zh" ? "版本" : "Version"} ${item.version}`;
          const status = document.createElement("small");
          status.textContent = index === 0 ? translations[currentLanguage].latest : "";
          option.append(label, status);
          option.addEventListener("click", () => {
            previewVersion = item.version;
            renderVersionDialog();
          });
          versionList.append(option);
        });

        versionNotes.replaceChildren();
        for (const note of release.notes ?? []) {
          const item = document.createElement("li");
          item.textContent = note;
          versionNotes.append(item);
        }

        versionDialogConfirm.textContent = `${translations[currentLanguage].useVersion} ${release.version}`;
      }

      controllerSelect.addEventListener("change", () => {
        selectManifest();
      });

      versionMenuButton.addEventListener("click", () => {
        if (releases.length === 0) return;
        previewVersion = selectedVersion;
        renderVersionDialog();
        versionDialog.showModal();
      });

      versionDialogClose.addEventListener("click", () => versionDialog.close());
      versionDialogConfirm.addEventListener("click", () => {
        selectedVersion = previewVersion;
        selectManifest();
        versionDialog.close();
      });

      fetch("releases.json", { cache: "no-store" })
        .then((response) => {
          if (!response.ok) throw new Error(`HTTP ${response.status}`);
          return response.json();
        })
        .then((releaseIndex) => {
          releases = releaseIndex.versions.slice(0, 10);
          selectedVersion = releases[0]?.version ?? "";
          selectManifest();
        })
        .catch(() => {
          versionLabel.textContent = translations[currentLanguage].unavailable;
          versionMenuButton.disabled = true;
        });
    </script>
  </body>
</html>