修改前
status.textContent = "尚未完成載入流程";
修改後
function isGasExecUrl(value) {
try {
const url = new URL(value);
return url.protocol === "https:"
&& url.hostname === "script.google.com"
&& /^\/macros\/s\/[^/]+\/exec$/.test(url.pathname);
} catch {
return false;
}
}
function getSourceLabel(url) {
if (url === "mock") return "MOCK 備援";
if (url === "mock-empty") return "MOCK 空資料";
return isGasExecUrl(url) ? "LIVE GAS" : "CUSTOM JSON(非 GAS)";
}
const url = endpoint.value.trim() || "mock";
mode.textContent = getSourceLabel(url);
status.textContent = "載入中…";
try {
const rows = normalizeRows(await requestRows(url));
renderRows(rows);
status.textContent = rows.length === 0 ? "載入完成,目前沒有資料" : `載入 ${rows.length} 筆`;
} catch (error) {
mode.textContent = "MOCK 備援";
const rows = normalizeRows(await requestRows("mock"));
renderRows(rows);
status.textContent = `Live 失敗,已切備援:${error.message}`;
}