mirror of
https://git.openapi.site/https://github.com/desirecore/market.git
synced 2026-12-05 22:39:31 +08:00
- 准入 10 项 installable 技能:agent-reach、dingtalk-api、follow-builders、humanizer-zh、karpathy-guidelines、marketingskills、netease-skills、wecom-cli(原 pin 不变),以及完整 MIT 本地版 ai-news-radar(LearnPrompt/ai-news-radar@689395109cc962a27c369bdd6fa50d1e090eb319)和 ClawHub 1.1.1 完整 ZIP 的 amap-jsapi-skill(sha256 9468743ee18dbe1704e8a98f47f6628d6a4e6acec30a05f0b8f59a07603d011f)。 - 瑞幸、MiniMax 图片/语音、LumaRescue、美团跑腿、Ian 小黑、女娲 继续 listing-only。 - 高德许可按 SKILL.md 的 MIT 声明保守记录,skill-card/ClawHub 写 MIT-0 的差异已在 ADMISSION.md 披露。 - validate、translate 通过;CodeQL 对上游原样 update_news.py 的 5 条告警经 mashagua 确认忽略。
141 lines
4.3 KiB
JavaScript
141 lines
4.3 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);
|
|
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 (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 = preference || deviceDefault;
|
|
|
|
function destination(view) {
|
|
const url = new URL(view === "classic" ? "classic/" : "./", rootUrl);
|
|
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)) 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);
|
|
},
|
|
};
|
|
})();
|