diff --git a/README.md b/README.md index 6df0902..2e94cdf 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,7 @@ These add a page to magpie's window, in the app and in `magpie web`, under Plugi | Package | Page | Reads | |---|---|---| | [usage](packages/usage) | Usage glance: calls, errors, tokens and cost for today, 7 or 30 days, and the models behind them | `usage:summary` | +| [free-tokens](packages/free-tokens) | AIHOT's Token freebies in three tiers (already configured and usable / needs one more plugin / no plugin yet), with the plugin to install or the exact login step for each | none; its host part reads ~/.config/magpie (providers/checkin) on open and fetches aihot.news/free-tokens.data | | [day-card](packages/day-card) | Day card: a day of your usage drawn as a card (tokens, cost, each agent and its models, streak, average day), copied as a picture or saved as a PNG | `usage:day` | | [powercontext](packages/powercontext) | Connection settings for an independently deployed PowerContext service | None | | [nowledge-mem](packages/nowledge-mem) | Connection settings, recall and capture switches, a real connection test, and the scope of what is sent | None | diff --git a/packages/free-tokens/LICENSE b/packages/free-tokens/LICENSE new file mode 100644 index 0000000..fca7b15 --- /dev/null +++ b/packages/free-tokens/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Mingchen Yu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/free-tokens/NOTICE b/packages/free-tokens/NOTICE new file mode 100644 index 0000000..2c338c9 --- /dev/null +++ b/packages/free-tokens/NOTICE @@ -0,0 +1,10 @@ +This package bundles brand icons copied from magpie's own assets +(magpie: https://github.com/yetone/magpie, MIT License). + +Those icons originate from lobe-icons (https://github.com/lobehub/lobe-icons), +MIT License, Copyright (c) 2023 LobeHub. +License: https://github.com/lobehub/lobe-icons/blob/master/LICENSE + +The token freebies shown at runtime come from AIHOT (https://aihot.news/free-tokens), +fetched directly on each user's machine at runtime. No AIHOT data is bundled with +this package. diff --git a/packages/free-tokens/README.md b/packages/free-tokens/README.md new file mode 100644 index 0000000..a014221 --- /dev/null +++ b/packages/free-tokens/README.md @@ -0,0 +1,9 @@ +# @magpie-community/page-free-tokens + +AIHOT「Token 羊毛」页面:在 magpie 窗口里分三档看各家大模型的免费额度——**已配置可用** / **有插件待配置** / **暂无插件**,并对每条给出该装的插件或登录路径。 + +数据来自 [AIHOT · Token 羊毛](https://aihot.news/free-tokens),每个用户在自己的电脑上打开页面时直连读一次(不代理、不镜像、不随包分发、不后台轮询)。只展示官方厂商额度(`src/allowlist.js`);图标用 magpie 自带品牌图标,其余首字母色块。页脚署名「数据源:AIHOT」并链回。 + +> 已取得 AIHOT 书面授权(2026-11-10):免费、不接广告/赞助、每用户本机打开时读一次、不做代理/镜像/数据分发。 + +安装:`magpie plugin add @magpie-community/page-free-tokens`。测试:`bun test`(100% 行覆盖)。 diff --git a/packages/free-tokens/index.js b/packages/free-tokens/index.js new file mode 100644 index 0000000..5eff5e1 --- /dev/null +++ b/packages/free-tokens/index.js @@ -0,0 +1,6 @@ +// magpie-free-tokens host part:仅在页面打开(宿主启动)时拉一次 AIHOT、读本机 magpie、写 page/data.js。 +// 只导出 default {id, server}(不带任何命名导出,免得被 check.mjs 当插件函数调用)。 +import { refresh } from "./src/refresh.js"; + +const server = async (input) => { await refresh(input); return {}; }; +export default { id: "free-tokens", server }; diff --git a/packages/free-tokens/package.json b/packages/free-tokens/package.json new file mode 100644 index 0000000..50cacc1 --- /dev/null +++ b/packages/free-tokens/package.json @@ -0,0 +1,47 @@ +{ + "name": "@magpie-community/page-free-tokens", + "version": "0.1.0", + "description": "AIHOT Token 羊毛:在 magpie 里看哪些羊毛已配置可用、哪些差个插件、哪些还没插件。", + "type": "module", + "main": "./index.js", + "files": [ + "index.js", + "src/", + "page/", + "!page/data.js", + "README.md", + "NOTICE", + "LICENSE", + "test/" + ], + "keywords": [ + "magpie", + "magpie-page", + "magpie-plugin", + "free-tokens", + "aihot", + "token" + ], + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/magpie-community/plugins.git", + "directory": "packages/free-tokens" + }, + "magpie": { + "name": "Token 羊毛", + "icon": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2NCA2NCIgd2lkdGg9IjY0IiBoZWlnaHQ9IjY0IiByb2xlPSJpbWciIGFyaWEtbGFiZWw9IlRva2VuIOe+iuavmyI+CiAgPHJlY3Qgd2lkdGg9IjY0IiBoZWlnaHQ9IjY0IiByeD0iMTYiIGZpbGw9IiM0ZjQ2ZTUiLz4KICA8Y2lyY2xlIGN4PSIyOS41IiBjeT0iMzUuNSIgcj0iMTUiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2ZmZmZmZiIgc3Ryb2tlLXdpZHRoPSIzLjQiLz4KICA8cGF0aCBkPSJNMjMuOCAyOS4yIEwyOS41IDM2LjIgTDM1LjIgMjkuMiIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjZmZmZmZmIiBzdHJva2Utd2lkdGg9IjMiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPgogIDxwYXRoIGQ9Ik0yOS41IDM2LjIgVjQ0LjQiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2ZmZmZmZiIgc3Ryb2tlLXdpZHRoPSIzIiBzdHJva2UtbGluZWNhcD0icm91bmQiLz4KICA8cGF0aCBkPSJNMjQuNiAzOS4yIEgzNC40IE0yNC42IDQyLjQgSDM0LjQiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2ZmZmZmZiIgc3Ryb2tlLXdpZHRoPSIzIiBzdHJva2UtbGluZWNhcD0icm91bmQiLz4KICA8cGF0aCBkPSJNNDcgMTEuNSBsMiA1LjEgNS4xIDIgLTUuMSAyIC0yIDUuMSAtMiAtNS4xIC01LjEgLTIgNS4xIC0yIHoiIGZpbGw9IiNmZmZmZmYiLz4KPC9zdmc+Cg==", + "summary": { + "en": "AIHOT Token freebies: which you can use now, which need a magpie plugin, which have none.", + "zh": "AIHOT 的 Token 羊毛:哪些已能用、哪些差个插件、哪些还没插件。" + }, + "page": { + "title": "Token 羊毛", + "file": "page/index.html", + "icon": "page/icon.svg", + "titles": { + "en": "Token Freebies" + } + } + } +} \ No newline at end of file diff --git a/packages/free-tokens/page/app.js b/packages/free-tokens/page/app.js new file mode 100644 index 0000000..f116e92 --- /dev/null +++ b/packages/free-tokens/page/app.js @@ -0,0 +1,94 @@ +// Token 羊毛 · 紧凑三档视图(classic script;只读;跟随 magpie 主题;无外链、无网络请求)。 +// 依赖先加载的 view.js(window.FTView)。用 classic 而非 module:magpie 页面 frame 为 sandbox=allow-scripts, +// origin 为 null,module script 走 CORS 会被拒(见 review)。 +(function () { + "use strict"; + if (!window.FTView) { document.addEventListener("DOMContentLoaded", () => { const el = document.getElementById("list"); if (el) el.innerHTML = '
页面资源加载失败(view.js 未加载)
'; }); return; } + const V = window.FTView; + const { esc, bucketOf, counts, summaryHtml, rowHtml, actionOf } = V; + + const hasBridge = typeof window.magpie !== "undefined" && window.magpie && window.magpie.ready; + function previewBridge() { const dark = window.matchMedia && matchMedia("(prefers-color-scheme: dark)").matches; return { ready: Promise.resolve({ dark }), theme: { dark }, options: { get: async () => ({}), set: async (o) => o }, read: async () => ({}), onTheme() {} }; } + const MAG = hasBridge ? window.magpie : previewBridge(); + + const TABS = [["ready", "已配置可用", "已装好并登录,可直接用"], ["setup", "有插件待配置", "有插件,还没装或没登录"], ["none", "暂无插件", "还没有对应的 magpie 插件"]]; + const TAB_HINT = { + ready: "这些羊毛对应的供应商已在你的 magpie 里登录,可以直接使用;标「今日可领」的记得去签到。", + setup: "点「安装插件」会给出可粘贴的包名;到 magpie「插件 → 发现 → 已有想装的?」粘贴添加(页面无法直接跳转安装)。", + none: "这些还没有对应的 magpie 插件;「复制链接」可在浏览器打开来源。", + }; + + const $ = (s, r = document) => r.querySelector(s); + const $$ = (s, r = document) => Array.from(r.querySelectorAll(s)); + + let meta, deals, mapping, demoState, icons = {}; + let DATA_REF = null, wired = false; + const state = { tab: "ready", q: "" }; + function applyData(d) { meta = d.meta || {}; deals = Array.isArray(d.deals) ? d.deals : []; mapping = d.mapping || {}; demoState = d.demoState || { installed: {}, configKnown: true, checkinKnown: true }; icons = d.icons || {}; DATA_REF = d; } + function showUnavailable() { applyData({ meta: {}, deals: [], mapping: {}, demoState: { installed: {}, configKnown: true, checkinKnown: true } }); showMessage("数据源暂不可用(AIHOT 无法访问)。稍后重试。"); } + + function applyTheme(dark) { document.documentElement.dataset.theme = dark ? "dark" : "light"; } + function renderSummary(c) { $("#summary").innerHTML = summaryHtml(meta, deals.length, c); } + function renderBuckets(c) { const el = $("#buckets"); el.innerHTML = TABS.map(([k, label]) => ``).join(""); $$(".tile", el).forEach((b) => (b.onclick = () => { state.tab = b.dataset.tab; render(); })); } + function renderList() { + const q = state.q.trim().toLowerCase(); + const rows = deals.filter((d) => bucketOf(d, mapping, demoState).key === state.tab) + .filter((d) => !q || (d.provider + " " + d.title + " " + (d.tags || []).join(" ")).toLowerCase().includes(q)) + .sort((a, b) => (b.yuan || 0) - (a.yuan || 0) || a.provider.localeCompare(b.provider)); + const list = $("#list"); list.innerHTML = rows.map((d) => rowHtml(d, { mapping, demoState, icons })).join(""); + $("#empty").style.display = rows.length ? "none" : "block"; + $$(".avatar.logo img", list).forEach((img) => img.addEventListener("error", () => { const d = img.parentNode; d.className = "avatar gen"; d.style.background = d.getAttribute("data-col") || "#4f46e5"; d.textContent = d.getAttribute("data-ini") || "?"; })); + $$("[data-act]", list).forEach((btn) => btn.addEventListener("click", (e) => { e.stopPropagation(); onAction(btn); })); + } + function render() { + if (!deals) return; + const c = counts(deals, mapping, demoState); renderSummary(c); renderBuckets(c); + $("#tabhint").innerHTML = esc(TAB_HINT[state.tab] || ""); renderList(); + let when = ""; try { when = new Date(meta.generatedAt).toLocaleString("zh-CN", { timeZone: "Asia/Shanghai", hour12: false }); } catch { when = String(meta.generatedAt); } + const warn = demoState.configKnown ? "" : " · 读取本机 magpie 配置失败,档位可能不准"; + $("#footNote").textContent = `三档:已配置可用 / 有插件待配置 / 暂无插件;数据取自 AIHOT 实时 · ${when}(北京时间)${warn}。数据源:AIHOT · https://aihot.news/free-tokens`; + } + function showMessage(msg) { $("#list").innerHTML = `
${esc(msg)}
`; $("#empty").style.display = "none"; } + + function onAction(btn) { const a = actionOf(btn.dataset); if (a) popover(a); } + + async function copyText(txt) { try { if (navigator.clipboard && navigator.clipboard.writeText) { await navigator.clipboard.writeText(txt); return true; } } catch {} try { const ta = document.createElement("textarea"); ta.value = txt; ta.style.position = "fixed"; ta.style.top = "-1000px"; document.body.appendChild(ta); ta.focus(); ta.select(); const ok = document.execCommand("copy"); ta.remove(); return ok; } catch { return false; } } + function closePop() { const p = $("#pop-wrap"); if (p) p.remove(); } + function popover({ title, steps, copyText: ct }) { + closePop(); + const wrap = document.createElement("div"); wrap.id = "pop-wrap"; wrap.className = "pop-wrap"; + wrap.innerHTML = `
${esc(title)}
${steps && steps.length ? `
    ${steps.map((s) => `
  1. ${esc(s)}
  2. `).join("")}
` : ""}${ct ? `
` : ""}
`; + document.body.appendChild(wrap); + const input = wrap.querySelector("input"), tip = wrap.querySelector("[data-tip]"); + if (input) { input.focus(); input.select(); const tryCopy = async () => { const ok = await copyText(ct); if (tip) tip.textContent = ok ? "已复制到剪贴板" : "已全选,请按 ⌘C / Ctrl+C 手动复制"; }; tryCopy(); wrap.querySelector("[data-copy]").onclick = async () => { await tryCopy(); input.focus(); input.select(); }; } + wrap.querySelector(".pop-close").onclick = closePop; + wrap.addEventListener("click", (e) => { if (e.target === wrap) closePop(); }); + } + + function wire() { if (wired) return; wired = true; $("#q").addEventListener("input", (e) => { state.q = e.target.value; renderList(); }); } + function boot() { const d = window.__FREE_TOKENS__; if (!d) return false; if (d.error) { showUnavailable(); return true; } applyData(d); render(); return true; } + let tick = 0, tried = 0; + function inject() { + if (!hasBridge) return; + const s = document.createElement("script"); s.src = "data.js?t=" + Date.now() + "-" + (tick++); + s.onload = () => { const d = window.__FREE_TOKENS__; if (!d || d === DATA_REF) return; if (d.error) { showUnavailable(); } else { applyData(d); render(); } }; + s.onerror = () => {}; + document.head.appendChild(s); + } + + MAG.ready.then((theme) => { + applyTheme(!!(theme && theme.dark)); + if (MAG.onTheme) MAG.onTheme((t) => applyTheme(!!(t && t.dark))); + wire(); + if (hasBridge) { + inject(); + // 仅在有需要时重试几次(宿主可能稍后才写 data.js),不无限轮询 + const timer = setInterval(() => { + const d = window.__FREE_TOKENS__; + if (DATA_REF || (d && d.error) || ++tried >= 8) { clearInterval(timer); return; } + inject(); + }, 2000); + } + if (!boot()) { showMessage("数据准备中…"); setTimeout(() => { if (!DATA_REF) { const d = window.__FREE_TOKENS__; if (d && d.error) showUnavailable(); else showMessage("数据未就绪(请确认 AIHOT 可访问后重新打开此页)。"); } }, 16000); } + }); +})(); diff --git a/packages/free-tokens/page/brand/baidu-color.svg b/packages/free-tokens/page/brand/baidu-color.svg new file mode 100644 index 0000000..ead7f89 --- /dev/null +++ b/packages/free-tokens/page/brand/baidu-color.svg @@ -0,0 +1 @@ +Baidu \ No newline at end of file diff --git a/packages/free-tokens/page/brand/bailian-color.svg b/packages/free-tokens/page/brand/bailian-color.svg new file mode 100644 index 0000000..9acccd0 --- /dev/null +++ b/packages/free-tokens/page/brand/bailian-color.svg @@ -0,0 +1 @@ +BaiLian \ No newline at end of file diff --git a/packages/free-tokens/page/brand/cloudflare-color.svg b/packages/free-tokens/page/brand/cloudflare-color.svg new file mode 100644 index 0000000..d555b6f --- /dev/null +++ b/packages/free-tokens/page/brand/cloudflare-color.svg @@ -0,0 +1 @@ +Cloudflare \ No newline at end of file diff --git a/packages/free-tokens/page/brand/deepseek-color.svg b/packages/free-tokens/page/brand/deepseek-color.svg new file mode 100644 index 0000000..3fc2302 --- /dev/null +++ b/packages/free-tokens/page/brand/deepseek-color.svg @@ -0,0 +1 @@ +DeepSeek \ No newline at end of file diff --git a/packages/free-tokens/page/brand/doubao-color.svg b/packages/free-tokens/page/brand/doubao-color.svg new file mode 100644 index 0000000..e251145 --- /dev/null +++ b/packages/free-tokens/page/brand/doubao-color.svg @@ -0,0 +1 @@ +Doubao \ No newline at end of file diff --git a/packages/free-tokens/page/brand/huaweicloud-color.svg b/packages/free-tokens/page/brand/huaweicloud-color.svg new file mode 100644 index 0000000..4f5cd6a --- /dev/null +++ b/packages/free-tokens/page/brand/huaweicloud-color.svg @@ -0,0 +1 @@ +HuaweiCloud \ No newline at end of file diff --git a/packages/free-tokens/page/brand/hunyuan-color.svg b/packages/free-tokens/page/brand/hunyuan-color.svg new file mode 100644 index 0000000..42edd6c --- /dev/null +++ b/packages/free-tokens/page/brand/hunyuan-color.svg @@ -0,0 +1 @@ +Hunyuan \ No newline at end of file diff --git a/packages/free-tokens/page/brand/internlm-color.svg b/packages/free-tokens/page/brand/internlm-color.svg new file mode 100644 index 0000000..8e5daef --- /dev/null +++ b/packages/free-tokens/page/brand/internlm-color.svg @@ -0,0 +1 @@ +InternLM \ No newline at end of file diff --git a/packages/free-tokens/page/brand/minimax-color.svg b/packages/free-tokens/page/brand/minimax-color.svg new file mode 100644 index 0000000..beb7adb --- /dev/null +++ b/packages/free-tokens/page/brand/minimax-color.svg @@ -0,0 +1 @@ +Minimax \ No newline at end of file diff --git a/packages/free-tokens/page/brand/modelscope-color.svg b/packages/free-tokens/page/brand/modelscope-color.svg new file mode 100644 index 0000000..afbaa17 --- /dev/null +++ b/packages/free-tokens/page/brand/modelscope-color.svg @@ -0,0 +1 @@ +ModelScope \ No newline at end of file diff --git a/packages/free-tokens/page/brand/opencode.svg b/packages/free-tokens/page/brand/opencode.svg new file mode 100644 index 0000000..9c4cb89 --- /dev/null +++ b/packages/free-tokens/page/brand/opencode.svg @@ -0,0 +1 @@ +opencode \ No newline at end of file diff --git a/packages/free-tokens/page/brand/qoder.svg b/packages/free-tokens/page/brand/qoder.svg new file mode 100644 index 0000000..0ef248b --- /dev/null +++ b/packages/free-tokens/page/brand/qoder.svg @@ -0,0 +1 @@ +Qoder \ No newline at end of file diff --git a/packages/free-tokens/page/brand/sensenova-color.svg b/packages/free-tokens/page/brand/sensenova-color.svg new file mode 100644 index 0000000..17f1d82 --- /dev/null +++ b/packages/free-tokens/page/brand/sensenova-color.svg @@ -0,0 +1 @@ +SenseNova \ No newline at end of file diff --git a/packages/free-tokens/page/brand/siliconcloud-color.svg b/packages/free-tokens/page/brand/siliconcloud-color.svg new file mode 100644 index 0000000..6b5f6d8 --- /dev/null +++ b/packages/free-tokens/page/brand/siliconcloud-color.svg @@ -0,0 +1 @@ +SiliconCloud \ No newline at end of file diff --git a/packages/free-tokens/page/brand/stepfun-color.svg b/packages/free-tokens/page/brand/stepfun-color.svg new file mode 100644 index 0000000..920e8a6 --- /dev/null +++ b/packages/free-tokens/page/brand/stepfun-color.svg @@ -0,0 +1 @@ +Stepfun \ No newline at end of file diff --git a/packages/free-tokens/page/brand/tencentcloud-color.svg b/packages/free-tokens/page/brand/tencentcloud-color.svg new file mode 100644 index 0000000..4e7d033 --- /dev/null +++ b/packages/free-tokens/page/brand/tencentcloud-color.svg @@ -0,0 +1 @@ +TencentCloud \ No newline at end of file diff --git a/packages/free-tokens/page/brand/trae.svg b/packages/free-tokens/page/brand/trae.svg new file mode 100644 index 0000000..8f42e96 --- /dev/null +++ b/packages/free-tokens/page/brand/trae.svg @@ -0,0 +1 @@ +TRAE \ No newline at end of file diff --git a/packages/free-tokens/page/brand/volcengine-color.svg b/packages/free-tokens/page/brand/volcengine-color.svg new file mode 100644 index 0000000..ecf6d75 --- /dev/null +++ b/packages/free-tokens/page/brand/volcengine-color.svg @@ -0,0 +1 @@ +Volcengine \ No newline at end of file diff --git a/packages/free-tokens/page/brand/workbuddy-color.svg b/packages/free-tokens/page/brand/workbuddy-color.svg new file mode 100644 index 0000000..faf7e5d --- /dev/null +++ b/packages/free-tokens/page/brand/workbuddy-color.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/free-tokens/page/brand/zcode.png b/packages/free-tokens/page/brand/zcode.png new file mode 100644 index 0000000..377db60 Binary files /dev/null and b/packages/free-tokens/page/brand/zcode.png differ diff --git a/packages/free-tokens/page/brand/zed.svg b/packages/free-tokens/page/brand/zed.svg new file mode 100644 index 0000000..c286d0f --- /dev/null +++ b/packages/free-tokens/page/brand/zed.svg @@ -0,0 +1 @@ +Zed diff --git a/packages/free-tokens/page/brand/zhipu-color.svg b/packages/free-tokens/page/brand/zhipu-color.svg new file mode 100644 index 0000000..0c6e61c --- /dev/null +++ b/packages/free-tokens/page/brand/zhipu-color.svg @@ -0,0 +1 @@ +Zhipu \ No newline at end of file diff --git a/packages/free-tokens/page/icon.svg b/packages/free-tokens/page/icon.svg new file mode 100644 index 0000000..d7a2a73 --- /dev/null +++ b/packages/free-tokens/page/icon.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/packages/free-tokens/page/index.html b/packages/free-tokens/page/index.html new file mode 100644 index 0000000..ac10b6a --- /dev/null +++ b/packages/free-tokens/page/index.html @@ -0,0 +1,31 @@ + + + + + +Token 羊毛 + + + + + + +
+
+

Token 羊毛

+

看你的 magpie:哪些羊毛已能用、哪些差个插件、哪些还没插件 · 数据源 AIHOT

+
+
+

+
+

+ +
+ +

+
+ + diff --git a/packages/free-tokens/page/style.css b/packages/free-tokens/page/style.css new file mode 100644 index 0000000..0b2ff4c --- /dev/null +++ b/packages/free-tokens/page/style.css @@ -0,0 +1,113 @@ +/* 跟随 magpie 主题:优先用宿主注入的 --magpie-* 变量;无 bridge 时用回退值。 */ +:root { + --bg: var(--magpie-bg, #ffffff); + --fg: var(--magpie-fg, #1d1d1f); + --fg-2: var(--magpie-fg-2, var(--magpie-muted, #6e6e73)); + --muted: var(--magpie-muted, #6e6e73); + --line: var(--magpie-line, #e5e5ea); + --card: var(--magpie-card, #f6f6f7); + --pill: var(--magpie-pill, var(--magpie-card, #f0f0f2)); + --accent: var(--magpie-accent, #4f46e5); + --accent-soft: var(--magpie-accent-soft, rgba(79, 70, 229, .12)); + --accent-fg: var(--magpie-accent-fg, #ffffff); + --green: var(--magpie-green, #15803d); + --amber: var(--magpie-amber, #b45309); + --red: var(--magpie-red, #d70015); + --font: var(--magpie-font, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif); +} +@media (prefers-color-scheme: dark) { + :root { --bg: var(--magpie-bg, #1a1a1c); --fg: var(--magpie-fg, #ececef); --fg-2: var(--magpie-fg-2, var(--magpie-muted, #b4b4bc)); --muted: var(--magpie-muted, #9a9aa2); --line: var(--magpie-line, #33333a); --card: var(--magpie-card, #242428); --pill: var(--magpie-pill, #2c2c31); } +} +:root[data-theme="dark"] { + --bg: var(--magpie-bg, #1a1a1c); --fg: var(--magpie-fg, #ececef); --fg-2: var(--magpie-fg-2, var(--magpie-muted, #b4b4bc)); --muted: var(--magpie-muted, #9a9aa2); --line: var(--magpie-line, #33333a); --card: var(--magpie-card, #242428); --pill: var(--magpie-pill, #2c2c31); +} + +* { box-sizing: border-box; } +html, body { margin: 0; background: var(--bg); color: var(--fg); } +body { + padding: 20px 24px 32px; + font: 13px/1.45 var(--font); + -webkit-font-smoothing: antialiased; + text-rendering: optimizeLegibility; +} +button, input { font: inherit; } +h1 { font-size: 20px; font-weight: 600; letter-spacing: -.01em; margin: 0; } +.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; } +.sub { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); } + +.summary { margin: 12px 0 12px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; } +.summary b { color: var(--fg); font-weight: 600; } +.summary .sep { margin: 0 6px; opacity: .6; } + +/* 三个计数:官方 .tile 风格 */ +.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 6px; } +.tile { + display: flex; flex-direction: column; align-items: flex-start; gap: 2px; + background: var(--card); border: 1px solid var(--line); border-radius: 10px; + padding: 10px 12px; text-align: left; color: inherit; cursor: pointer; min-width: 0; + transition: border-color .14s ease, background .14s ease; +} +.tile:hover:not(.on) { border-color: color-mix(in srgb, var(--fg) 16%, var(--line)); } +.tile.on { border-color: var(--accent); background: var(--accent-soft); } +.tile .k { font-size: 12px; color: var(--muted); line-height: 1.2; } +.tile .v { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.15; } +.tile.on .v { color: var(--accent); } + +.hint { margin: 10px 0 12px; min-height: 1.45em; font-size: 12px; color: var(--muted); } + +.find { display: flex; align-items: center; gap: 7px; background: var(--card); border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px; margin-bottom: 6px; color: var(--muted); } +.find:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); } +.find input { flex: 1; min-width: 0; border: 0; outline: none; background: none; color: var(--fg); font-size: 12.5px; } +.find input::placeholder { color: var(--muted); } + +.list { margin-top: 2px; } +.row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); } +.row:last-child { border-bottom: 0; } + +.avatar { flex: none; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; overflow: hidden; font-size: 12px; font-weight: 600; color: #fff; } +.avatar.logo { background: #ffffff; border: 1px solid var(--line); } +.avatar.logo img { width: 19px; height: 19px; object-fit: contain; } +:root[data-theme="dark"] .avatar.logo { background: #eef0f4; border-color: #3a3a42; } + +.rmain { min-width: 0; } +.rprov { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); overflow: hidden; } +.tag { flex: none; font-size: 10.5px; font-weight: 500; padding: 0 6px; height: 16px; line-height: 16px; border-radius: 5px; background: var(--pill); color: var(--fg-2); } +.rtitle { font-size: 13px; font-weight: 500; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } +.rsub { display: flex; align-items: center; gap: 5px; margin-top: 1px; font-size: 12px; color: var(--muted); } +.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; } +.dot.ok { background: var(--green); } +.dot.warn { background: var(--amber); } +.dot.mut { background: var(--muted); opacity: .55; } + +.rright { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; } +.rval { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; } +.rval small { display: block; font-size: 11px; font-weight: 400; color: var(--muted); } +.cta { font-size: 12px; font-weight: 500; white-space: nowrap; color: var(--fg-2); background: var(--card); border: 1px solid var(--line); border-radius: 7px; padding: 3px 9px; cursor: pointer; transition: background .14s, color .14s, border-color .14s; } +.cta:hover { color: var(--fg); border-color: color-mix(in srgb, var(--fg) 16%, var(--line)); } +.cta.primary { color: var(--accent); background: var(--accent-soft); border-color: transparent; } +.cta.primary:hover { color: var(--accent-fg); background: var(--accent); } + +.empty { color: var(--muted); margin: 14px 0; font-size: 13px; } +.foot-note { color: var(--muted); font-size: 11.5px; line-height: 1.5; margin: 16px 0 0; } + +/* 气泡(安装 / 登录 / 复制链接) */ +.pop-wrap { position: fixed; inset: 0; background: rgba(0, 0, 0, .22); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; } +.pop { width: 440px; max-width: 92vw; max-height: 82vh; overflow: auto; background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: 0 12px 40px rgba(0, 0, 0, .22); } +.pop-h { font-size: 13px; font-weight: 600; margin-bottom: 8px; } +.pop-steps { margin: 0 0 10px; padding-left: 18px; font-size: 12.5px; line-height: 1.55; color: var(--fg-2); } +.pop-copy { display: flex; gap: 6px; align-items: center; } +.pop-copy input { flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; color: var(--fg); font-family: var(--magpie-code, ui-monospace, Menlo, monospace); font-size: 12px; } +.pop-btn { font-size: 12px; color: var(--accent); background: var(--accent-soft); border: 0; border-radius: 6px; padding: 4px 10px; cursor: pointer; } +.pop-tip { min-height: 1.3em; font-size: 11.5px; color: var(--muted); margin-top: 4px; } +.pop-foot { display: flex; justify-content: flex-end; margin-top: 12px; } +.pop-close { font-size: 12px; color: var(--fg-2); background: var(--card); border: 1px solid var(--line); border-radius: 7px; padding: 4px 12px; cursor: pointer; } + +.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--fg); color: var(--bg); font-size: 12px; padding: 6px 12px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .18s; } +.toast.show { opacity: 1; } + +@media (max-width: 560px) { + body { padding: 16px 16px 24px; } + .tiles { gap: 8px; } + .tile { padding: 8px 10px; } + .tile .v { font-size: 18px; } +} diff --git a/packages/free-tokens/page/view.js b/packages/free-tokens/page/view.js new file mode 100644 index 0000000..1766cbd --- /dev/null +++ b/packages/free-tokens/page/view.js @@ -0,0 +1,58 @@ +// 纯渲染逻辑(无 DOM/网络)。浏览器里作为 classic