mirror of
https://git.openapi.site/https://github.com/desirecore/market.git
synced 2026-12-05 09:39:21 +08:00
## 概述 / 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)。
147 lines
4.8 KiB
JavaScript
147 lines
4.8 KiB
JavaScript
(function () {
|
|
"use strict";
|
|
|
|
const STORAGE_KEY = "aiNewsRadarViewV2";
|
|
const LEGACY_STORAGE_KEY = "aiNewsRadarView";
|
|
const MOBILE_OVERRIDE_KEY = "aiNewsRadarMobileViewOnce";
|
|
const MOBILE_BREAKPOINT = "(max-width: 760px)";
|
|
const VALID_VIEWS = new Set(["mobile", "classic"]);
|
|
const script = document.currentScript;
|
|
const rootHint = script?.dataset.root || "./";
|
|
const rootUrl = new URL(rootHint, window.location.href);
|
|
// 英文版(data-root=/en/)只有手机版一个视角:经典版暂无英文,不渲染入口,也不读取/写入视角偏好。
|
|
const classicAvailable = !/^\/en\/?$/.test(rootHint);
|
|
const currentView = document.documentElement.dataset.radarView || "mobile";
|
|
const params = new URLSearchParams(window.location.search);
|
|
const requestedView = params.get("view") || "";
|
|
const isMobileViewport = window.matchMedia(MOBILE_BREAKPOINT).matches;
|
|
|
|
try {
|
|
window.localStorage.removeItem(LEGACY_STORAGE_KEY);
|
|
} catch {
|
|
// Storage can be unavailable in private or hardened browser contexts.
|
|
}
|
|
|
|
function readPreference() {
|
|
try {
|
|
const value = window.localStorage.getItem(STORAGE_KEY) || "";
|
|
return VALID_VIEWS.has(value) ? value : "";
|
|
} catch {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
function writePreference(view) {
|
|
try {
|
|
if (VALID_VIEWS.has(view)) {
|
|
window.localStorage.setItem(STORAGE_KEY, view);
|
|
} else {
|
|
window.localStorage.removeItem(STORAGE_KEY);
|
|
}
|
|
} catch {
|
|
// Storage can be unavailable in private or hardened browser contexts.
|
|
}
|
|
}
|
|
|
|
function readMobileOverride() {
|
|
try {
|
|
const value = window.sessionStorage.getItem(MOBILE_OVERRIDE_KEY) || "";
|
|
window.sessionStorage.removeItem(MOBILE_OVERRIDE_KEY);
|
|
return VALID_VIEWS.has(value) ? value : "";
|
|
} catch {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
function writeMobileOverride(view) {
|
|
try {
|
|
if (VALID_VIEWS.has(view)) {
|
|
window.sessionStorage.setItem(MOBILE_OVERRIDE_KEY, view);
|
|
} else {
|
|
window.sessionStorage.removeItem(MOBILE_OVERRIDE_KEY);
|
|
}
|
|
} catch {
|
|
// Storage can be unavailable in private or hardened browser contexts.
|
|
}
|
|
}
|
|
|
|
if (!classicAvailable) {
|
|
// 英文版:忽略 ?view= 与已存偏好,不动 localStorage 里中文站的视角选择
|
|
} else if (requestedView === "auto") {
|
|
writePreference("");
|
|
writeMobileOverride("");
|
|
} else if (!isMobileViewport && VALID_VIEWS.has(requestedView)) {
|
|
writePreference(requestedView);
|
|
}
|
|
|
|
const mobileOverride = isMobileViewport ? readMobileOverride() : "";
|
|
const preference = isMobileViewport
|
|
? mobileOverride
|
|
: (requestedView === "auto"
|
|
? ""
|
|
: (VALID_VIEWS.has(requestedView) ? requestedView : readPreference()));
|
|
const deviceDefault = "mobile";
|
|
const targetView = classicAvailable ? (preference || deviceDefault) : deviceDefault;
|
|
|
|
function destination(view) {
|
|
const url = new URL(view === "classic" ? "classic/" : "./", rootUrl);
|
|
// trailingSlash=false 时 /en/ 会 308 到 /en,规范地址不带斜杠
|
|
if (url.pathname === "/en/") url.pathname = "/en";
|
|
const passthrough = new URLSearchParams(window.location.search);
|
|
passthrough.delete("view");
|
|
url.search = passthrough.toString();
|
|
url.hash = window.location.hash;
|
|
return url;
|
|
}
|
|
|
|
function cleanViewQuery() {
|
|
if (!requestedView) return;
|
|
const cleanUrl = destination(currentView);
|
|
window.history.replaceState(null, "", `${cleanUrl.pathname}${cleanUrl.search}${cleanUrl.hash}`);
|
|
}
|
|
|
|
function chooseView(view) {
|
|
if (!VALID_VIEWS.has(view) || !classicAvailable) return;
|
|
if (isMobileViewport) writeMobileOverride(view);
|
|
else writePreference(view);
|
|
if (view === currentView) return;
|
|
window.location.assign(destination(view).href);
|
|
}
|
|
|
|
if (targetView !== currentView) {
|
|
window.location.replace(destination(targetView).href);
|
|
return;
|
|
}
|
|
|
|
cleanViewQuery();
|
|
|
|
function mountSwitches() {
|
|
document.querySelectorAll("[data-radar-view-target]").forEach((button) => {
|
|
const view = button.dataset.radarViewTarget || "";
|
|
const active = view === currentView;
|
|
button.classList.toggle("is-active", active);
|
|
button.setAttribute("aria-pressed", active ? "true" : "false");
|
|
if (active) button.setAttribute("aria-current", "page");
|
|
else button.removeAttribute("aria-current");
|
|
button.addEventListener("click", () => chooseView(view));
|
|
});
|
|
}
|
|
|
|
if (document.readyState === "loading") {
|
|
document.addEventListener("DOMContentLoaded", mountSwitches, { once: true });
|
|
} else {
|
|
mountSwitches();
|
|
}
|
|
|
|
window.AINewsRadarView = {
|
|
current: currentView,
|
|
preference: preference || "auto",
|
|
choose: chooseView,
|
|
reset() {
|
|
writePreference("");
|
|
writeMobileOverride("");
|
|
window.location.replace(destination(deviceDefault).href);
|
|
},
|
|
};
|
|
})();
|