AkurAI Build
Menu

Public repository / 4fac5c7826068a0d615a09851633816b41204468

AkurAI-Notes / site/frontend/app.js

Latest change 9846363ea7fea56c5079985945447933709e6726 - fix: restore Notes app SSR routes by Claude Code

(function () {
  "use strict";

  function init() {
    const el = document.getElementById("health");
    if (el) {
      fetch("/api/health", { headers: { accept: "application/json" } })
        .then((r) => (r.ok ? r.json() : Promise.reject(new Error(`status ${r.status}`))))
        .then((d) => {
          const label = d.framework && d.version ? `${d.framework} ${d.version}` : "AkurAI-Notes";
          el.textContent = `server up ยท ${label}`;
          el.classList.add("ok");
        })
        .catch((e) => (el.textContent = `server unreachable: ${e.message}`));
    }
  }

  if (document.readyState === "loading") {
    document.addEventListener("DOMContentLoaded", init);
  } else {
    init();
  }
})();

(function copyInit() {
  "use strict";

  function fallbackCopy(text) {
    var ta = document.createElement("textarea");
    ta.value = text;
    ta.setAttribute("readonly", "");
    ta.style.position = "absolute";
    ta.style.left = "-9999px";
    document.body.appendChild(ta);
    ta.select();
    var ok = false;
    try {
      ok = document.execCommand("copy");
    } catch (e) {
      ok = false;
    }
    document.body.removeChild(ta);
    return ok;
  }

  function flash(btn) {
    if (btn.dataset.copyBusy === "1") return;
    btn.dataset.copyBusy = "1";
    var original = btn.textContent;
    btn.textContent = "Copied!";
    btn.classList.add("is-copied");
    setTimeout(function () {
      btn.textContent = original;
      btn.classList.remove("is-copied");
      delete btn.dataset.copyBusy;
    }, 1500);
  }

  function bind(widget) {
    var btn = widget.querySelector("[data-copy-btn]");
    if (!btn) return;
    btn.addEventListener("click", function () {
      var text = widget.getAttribute("data-clipboard") || "";
      if (!text) return;
      if (navigator.clipboard && navigator.clipboard.writeText) {
        navigator.clipboard.writeText(text).then(
          function () { flash(btn); },
          function () { if (fallbackCopy(text)) flash(btn); }
        );
      } else if (fallbackCopy(text)) {
        flash(btn);
      }
    });
  }

  function copyStart() {
    document.querySelectorAll("[data-clipboard]").forEach(bind);
  }

  if (document.readyState === "loading") {
    document.addEventListener("DOMContentLoaded", copyStart);
  } else {
    copyStart();
  }
})();