35 lines
1.8 KiB
TypeScript
35 lines
1.8 KiB
TypeScript
|
|
"use client";
|
||
|
|
|
||
|
|
import { useEffect } from "react";
|
||
|
|
|
||
|
|
/** TEMP-DEBUG: เปิด Eruda (devtools ลอยบนหน้าจอ — ปุ่ม gear มุมขวาล่าง) เมื่อเปิด
|
||
|
|
* หน้าพร้อม ?debug ไว้อ่าน console.warn ของ log [debug] บน iPad จริง (ไม่มี Mac
|
||
|
|
* ต่อ Safari Web Inspector) — โหลดสคริปต์จาก CDN เท่านั้น ไม่แตะ dependencies
|
||
|
|
* ของ project — เคลียร์ debug เสร็จ = ลบไฟล์นี้ + บรรทัด import/render ใน
|
||
|
|
* app/annotate/[id]/page.tsx */
|
||
|
|
export default function DebugConsole() {
|
||
|
|
useEffect(() => {
|
||
|
|
if (!new URLSearchParams(window.location.search).has("debug")) return;
|
||
|
|
// React strict mode รัน effect สองรอบ — กัน append script ซ้ำ
|
||
|
|
if (document.getElementById("eruda-loader")) return;
|
||
|
|
const s = document.createElement("script");
|
||
|
|
s.id = "eruda-loader";
|
||
|
|
s.src = "https://cdn.jsdelivr.net/npm/eruda@3";
|
||
|
|
s.async = true;
|
||
|
|
s.onload = () => {
|
||
|
|
const w = window as unknown as { eruda?: { create: () => void } };
|
||
|
|
w.eruda?.create();
|
||
|
|
};
|
||
|
|
s.onerror = () => {
|
||
|
|
const b = document.createElement("div");
|
||
|
|
b.textContent =
|
||
|
|
"โหลด Eruda จาก CDN ไม่ได้ (iPad ต้องต่ออินเทอร์เน็ต) — แจ้งเพื่อเปลี่ยนเป็น bundle ใน project แทน";
|
||
|
|
b.style.cssText =
|
||
|
|
"position:fixed;top:0;left:0;right:0;z-index:99999;background:#dc2626;color:#fff;padding:8px;font-size:14px";
|
||
|
|
document.body.appendChild(b);
|
||
|
|
};
|
||
|
|
document.head.appendChild(s);
|
||
|
|
}, []);
|
||
|
|
return null;
|
||
|
|
}
|