Files
market/skills/ai-news-radar/assets/service-status.js
T
mashagua 0e9ae3b4a1 feat(ai-news-radar): 调和冲突并升级本地 MIT 包至 3c663dd (2026.12.01) (#418)
## 概述 / Summary

手工三方调和并升级 `ai-news-radar` 本地 MIT 派生包:`LearnPrompt/ai-news-radar`
`689395109cc962a27c369bdd6fa50d1e090eb319`(`2026.11.24`)→
`3c663ddab7da78e62365e1ee0e58f34cc9cef09a`(`2026.12.01`,与
`9fda56e8c82aca27e2e0fecbbe383a231a89311f` 相比所有受跟踪代码/文档文件逐字节一致,仅
`data/*` 有新快照)。

### 冲突调和与同步明细
1. **`assets/styles.css`**:合入上游新增的「今天值得做」卡片样式,并与上游逐字节对齐(消除此前仅 1
处末尾空行差异,避免后续 CSS 更新再次触发冲突)。
2. **`classic/index.html`**:合入上游新区块与静态资源版本号,继续保留适配 `<base href="../">` 的
`./assets/service-status.*` 路径修正。
3. **`README.md` / `references/upstream-project-readme*.md` /
`docs/SOURCE_COVERAGE.md`**:根目录 `README.md` 保留本地安装说明;上游新
`README.md`、`README.en.md` 与 `docs/SOURCE_COVERAGE.md`
同步到对应引用位置,保留引用声明头与固定 commit 链接。
4. **同步其余受跟踪上游文件 & 补齐新引用资源**:同步
`scripts/update_news.py`、`index.html`、`assets/app.js`、`assets/service-status.js`、`assets/view-mode.js`、`classic/assets/app.js`、`classic/assets/styles.css`;补齐新版
`index.html` 引用的
`assets/i18n.js`、`assets/i18n/zh.js`、`assets/i18n/en.js`(避免断链)。继续排除
`#350` 明确不安装的 `data/`、测试与上游工作流。
5. **元数据与映射同步**:同步更新
`config/verified-updates.v1.json`、`skills/ai-news-radar/UPSTREAM.md`、`skills/ai-news-radar/catalog-metadata.v1.json`。

## 验证 / Validation
- `python3 -B skills/ai-news-radar/scripts/update_news.py --help`
- `uv run --offline --quiet --with pytest --with pyyaml --with
jsonschema python -m pytest scripts/catalog/test_tracked_updates.py -q`
- `uv run --offline --quiet scripts/catalog/validate_catalog_metadata.py
--require-complete`
- `uv run --offline --quiet scripts/i18n/validate-i18n.py`
- `uv run --offline --quiet scripts/i18n/translate.py --check`
- `git diff --check`

合并后可关闭仅记录阻断状态的旧草稿 [#399](https://github.com/desirecore/market/pull/399)。
2026-12-01 20:41:51 +08:00

180 lines
6.3 KiB
JavaScript

(() => {
const panel = document.getElementById("serviceStatusPanel");
if (!panel) return;
// i18n 由 assets/i18n.js 提供(先于本文件加载)。经典版页面不加载 i18n,退回下面这份中文词条
// (与 assets/i18n/zh.json 的 svc.* 一致,由 tests/i18n.test.mjs 校验)。
const i18n = window.AINewsRadarI18n;
const ZH_FALLBACK = {
"svc.investigating": "调查中",
"svc.identified": "已定位",
"svc.monitoring": "恢复监控中",
"svc.elevatedErrors": "OpenAI 服务错误率升高",
"svc.incidentFallback": "服务异常",
"svc.processing": "处理中",
"svc.heading": "ChatGPT / OpenAI 服务状态",
"svc.count": "{n} 项官方故障",
"svc.aria": "ChatGPT 与 OpenAI 服务状态:{n} 项故障正在处理",
};
const t = i18n
? i18n.t
: (key, params) => String(ZH_FALLBACK[key] || key).replace(/\{(\w+)\}/g, (whole, name) => (params && name in params ? String(params[name]) : whole));
const IS_EN = Boolean(i18n && i18n.isEN);
const LOCALE = i18n ? i18n.locale : "zh-CN";
const STATUS_LABELS = {
investigating: t("svc.investigating"),
identified: t("svc.identified"),
monitoring: t("svc.monitoring"),
};
function resolveDataBaseUrl() {
try {
const fromQuery = new URLSearchParams(window.location.search).get("data") || "";
if (fromQuery) return fromQuery.trim().replace(/\/+$/, "");
return (localStorage.getItem("dataBaseUrl") || "").trim().replace(/\/+$/, "");
} catch {
return "";
}
}
function dataUrl(path) {
const base = resolveDataBaseUrl();
if (!base) return path;
return `${base}/${String(path || "").split("/").pop()}`;
}
function formatTime(value) {
const date = new Date(value || "");
if (Number.isNaN(date.getTime())) return "";
return new Intl.DateTimeFormat(LOCALE, {
month: "numeric",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
hour12: false,
}).format(date);
}
function providerLabel(incident) {
const components = Array.isArray(incident?.affected_components)
? incident.affected_components
: [];
const signal = [incident?.title, incident?.title_zh, ...components]
.filter(Boolean)
.join(" ")
.toLowerCase();
if (signal.includes("chatgpt")) return "ChatGPT";
return incident?.provider || "OpenAI";
}
function incidentTitle(incident) {
if (incident?.title === "Elevated Error Rates") {
return t("svc.elevatedErrors");
}
// 英文版只用官方英文标题,不取 title_zh
return (IS_EN ? incident?.title : (incident?.title_zh || incident?.title)) || t("svc.incidentFallback");
}
function incidentNode(incident) {
const row = document.createElement("article");
row.className = `service-incident impact-${incident.impact || "none"}`;
const main = document.createElement("div");
main.className = "service-incident-main";
const meta = document.createElement("div");
meta.className = "service-incident-meta";
const provider = document.createElement("span");
provider.className = "service-provider";
provider.textContent = providerLabel(incident);
const phase = document.createElement("span");
phase.className = "service-phase";
phase.textContent = STATUS_LABELS[incident.status] || incident.status || t("svc.processing");
meta.append(provider, phase);
const title = document.createElement("a");
title.className = "service-incident-title";
const incidentUrl = new URL(incident.url || "", "https://status.openai.com/");
title.href = incidentUrl.protocol === "https:" && incidentUrl.hostname === "status.openai.com"
? incidentUrl.href : "https://status.openai.com/";
title.target = "_blank";
title.rel = "noopener noreferrer";
title.textContent = incidentTitle(incident);
main.append(meta, title);
const time = document.createElement("time");
time.className = "service-incident-time";
time.dateTime = incident.updated_at || "";
time.textContent = formatTime(incident.updated_at);
row.append(main, time);
return row;
}
function render(payload) {
const incidents = Array.isArray(payload?.incidents)
? payload.incidents.filter((incident) => incident && incident.status !== "resolved")
: [];
const generatedAt = Date.parse(payload?.generated_at || "");
const stale = !Number.isFinite(generatedAt) || Date.now() - generatedAt > 2 * 60 * 60 * 1000;
panel.replaceChildren();
if (payload?.ok !== true || stale || incidents.length === 0) {
panel.hidden = true;
return;
}
const heading = document.createElement("div");
heading.className = "service-status-heading";
const titleWrap = document.createElement("div");
titleWrap.className = "service-status-title-wrap";
const dot = document.createElement("span");
dot.className = "service-status-dot";
dot.setAttribute("aria-hidden", "true");
const title = document.createElement("strong");
title.textContent = t("svc.heading");
titleWrap.append(dot, title);
const count = document.createElement("span");
count.className = "service-status-count";
count.textContent = t("svc.count", { n: incidents.length });
heading.append(titleWrap, count);
const list = document.createElement("div");
list.className = "service-incident-list";
incidents.slice(0, 3).forEach((incident) => list.appendChild(incidentNode(incident)));
panel.append(heading, list);
panel.classList.toggle(
"has-major",
incidents.some((incident) => ["major", "critical"].includes(incident.impact)),
);
panel.hidden = false;
panel.setAttribute("aria-label", t("svc.aria", { n: incidents.length }));
}
const controller = new AbortController();
const timeout = window.setTimeout(() => controller.abort(), 8000);
fetch(dataUrl(new URL("../data/service-status.json", document.currentScript.src).href), {
cache: "no-cache",
headers: { Accept: "application/json" },
signal: controller.signal,
})
.then((response) => {
if (!response.ok) throw new Error(`service status ${response.status}`);
return response.json();
})
.then(render)
.catch(() => {
panel.hidden = true;
})
.finally(() => {
window.clearTimeout(timeout);
});
})();