notify 0.1.4: a sidebar page to edit channels and settings, and a switch that turns every push off (meili145 on X)
The page (magpie.page) edits the plugin's options without a file: add, pause and remove channels per kind, when to send, agents, language, and an on/off switch that saves at once (new option enabled, default true; off sends no turn push and no sign-in push). Run: bun test packages/notify (67 pass; the enabled test fails on the old hook), scripts/check.mjs ok. Page tried in magpie's real window (dev build of origin/main, sandbox HOME, plugin added from the folder) in chromium: add ntfy channel, Save and the switch wrote plugins.json options, 5 languages at 1000px and 420px with no overflow. Not tried: WebKit (its launch failed on mote), a real push from the page.
This commit is contained in:
@@ -46,10 +46,15 @@ A Claude sign-in that ends within days is pushed the same way ("sign-in ends in
|
||||
|
||||
The hook changes nothing in a request, and sending never holds one up: it returns at once and posts in the background, with a 10-second limit per channel.
|
||||
|
||||
## The page
|
||||
|
||||
The plugin has a page in magpie's sidebar (Plugins group): add, edit and pause channels, set when it sends, and turn every push on or off, without editing a file. The switch at the top is the `enabled` option; the rest of the page edits the options below and saves them whole, so a field it has no box for (a webhook's `headers`, a Gotify channel's `extras`) is kept. Pushes are never sent from the page itself.
|
||||
|
||||
## Options
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"enabled": true, // false: nothing is sent, channels stay
|
||||
"channels": [ // one or more; each sends the same push
|
||||
{ "type": "ntfy", "topic": "…", "server": "https://ntfy.sh", "token": "…", "priority": 3 },
|
||||
{ "type": "bark", "key": "…", "server": "https://api.day.app", "group": "magpie", "sound": "…" },
|
||||
|
||||
@@ -51,6 +51,7 @@ let cancel = (t) => clearTimeout(t)
|
||||
let pending = new Set()
|
||||
|
||||
export const defaults = {
|
||||
enabled: true,
|
||||
channels: [],
|
||||
minMinutes: 3,
|
||||
cooldownSeconds: 30,
|
||||
@@ -93,6 +94,9 @@ export function options(raw) {
|
||||
o.cooldownSeconds = Math.max(0, Number(o.cooldownSeconds) || 0)
|
||||
o.failureHoldSeconds = Math.max(0, Math.min(600, Number(o.failureHoldSeconds ?? defaults.failureHoldSeconds) || 0))
|
||||
o.maxTextLength = Math.max(0, Math.min(2000, Number(o.maxTextLength) || 0))
|
||||
o.enabled = o.enabled !== false
|
||||
// the page's switch: off sends nothing, whatever the channels
|
||||
if (!o.enabled) o.channels = []
|
||||
o.accounts = o.accounts !== false
|
||||
o.accountCooldownMinutes = Math.max(0, Number(o.accountCooldownMinutes ?? defaults.accountCooldownMinutes) || 0)
|
||||
if (!words[o.lang]) o.lang = "en"
|
||||
|
||||
@@ -885,3 +885,21 @@ test("a webhook gets the sign-in event", async () => {
|
||||
event: { kind: "signed-out", provider: "codex", account: "me@example.com" },
|
||||
})
|
||||
})
|
||||
|
||||
// meili145 on X: the page's switch turns every push off without touching channels
|
||||
test("enabled: false sends no turn push and no sign-in push, enabled by default", async () => {
|
||||
await exchange("anthropic", aUser, aFinal, { options: { minMinutes: 0, enabled: false } })
|
||||
onSignIn(signedOut, signInCtx({ enabled: false }))
|
||||
await settled()
|
||||
expect(calls.length).toBe(0)
|
||||
await exchange("anthropic", aUser, aFinal, { options: { minMinutes: 0 } })
|
||||
expect(calls.length).toBe(1)
|
||||
})
|
||||
|
||||
// the page ships with the package and keeps what it doesn't edit
|
||||
test("the page is declared and shipped", () => {
|
||||
const pkg = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"))
|
||||
expect(pkg.magpie.page.file).toBe("page/index.html")
|
||||
for (const f of ["index.html", "app.js", "i18n.js", "style.css"]) expect(readdirSync(new URL("./page/", import.meta.url))).toContain(f)
|
||||
expect(pkg.files).toEqual(expect.arrayContaining(["page/*.html", "page/*.js", "page/*.css"]))
|
||||
})
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
{
|
||||
"name": "@magpie-community/gateway-notify",
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"description": "A push to your phone or team chat when an agent's turn is done or an account is signed out: ntfy, Bark, Gotify, Server酱, Feishu, DingTalk, WeCom, Telegram or a webhook",
|
||||
"type": "module",
|
||||
"files": ["notify.hooks.mjs", "turn.mjs", "channels.mjs", "README.md"],
|
||||
"files": ["notify.hooks.mjs", "turn.mjs", "channels.mjs", "page/*.html", "page/*.js", "page/*.css", "README.md"],
|
||||
"keywords": ["magpie", "magpie-gateway", "magpie-hooks", "notification", "ntfy", "bark", "gotify", "feishu", "dingtalk", "telegram"],
|
||||
"license": "MIT",
|
||||
"repository": { "type": "git", "url": "git+https://github.com/magpie-community/plugins.git", "directory": "packages/notify" },
|
||||
"magpie": {
|
||||
"hooks": "./notify.hooks.mjs",
|
||||
"page": { "title": "Notify", "titles": { "zh": "通知", "zh-TW": "通知", "ja": "通知", "de": "Benachrichtigungen" }, "file": "page/index.html" },
|
||||
"options": {
|
||||
"enabled": true,
|
||||
"channels": [{ "type": "ntfy", "topic": "" }],
|
||||
"minMinutes": 3,
|
||||
"cooldownSeconds": 30,
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
// Notify's page: the plugin's options, edited without touching a file.
|
||||
// Everything is drawn from the saved options and written back whole, so a
|
||||
// field this page doesn't know (a webhook's headers, a Gotify channel's
|
||||
// extras) is kept as it was.
|
||||
(function () {
|
||||
"use strict"
|
||||
var t = window.NotifyI18n.t
|
||||
var root = document.getElementById("root")
|
||||
|
||||
var DEFAULTS = { enabled: true, channels: [], minMinutes: 3, cooldownSeconds: 30, errors: true, agents: [], allOrigins: false, includeText: false, accounts: true, lang: "en" }
|
||||
// kind -> { name, fields: [key, label, kind, required] }
|
||||
var KINDS = {
|
||||
ntfy: { name: "ntfy", fields: [["topic", "Topic", "text", 1], ["server", "Server", "text"], ["token", "Token", "secret"], ["priority", "Priority", "number"]] },
|
||||
bark: { name: "Bark", fields: [["key", "Key", "secret", 1], ["server", "Server", "text"], ["group", "Group", "text"], ["sound", "Sound", "text"]] },
|
||||
gotify: { name: "Gotify", fields: [["server", "Server", "text", 1], ["token", "Token", "secret", 1], ["priority", "Priority", "number"]] },
|
||||
serverchan: { name: "Server酱", fields: [["key", "Key", "secret", 1]] },
|
||||
feishu: { name: "Feishu", fields: [["webhook", "Webhook URL", "secret", 1], ["secret", "Secret", "secret"]] },
|
||||
dingtalk: { name: "DingTalk", fields: [["webhook", "Webhook URL", "secret", 1], ["secret", "Secret", "secret"]] },
|
||||
wecom: { name: "WeCom", fields: [["webhook", "Webhook URL", "secret", 1]] },
|
||||
telegram: { name: "Telegram", fields: [["token", "Token", "secret", 1], ["chatId", "Chat ID", "text", 1]] },
|
||||
webhook: { name: "Custom webhook", fields: [["url", "Webhook URL", "text", 1]] }
|
||||
}
|
||||
var LANGS = [["en", "English"], ["zh", "中文"]]
|
||||
|
||||
var saved = null // the options as the plugin has them
|
||||
var draft = null // what the page shows
|
||||
var note = ["", false]
|
||||
var busy = false
|
||||
var openMenu = null
|
||||
|
||||
function el(tag, cls, text) {
|
||||
var n = document.createElement(tag)
|
||||
if (cls) n.className = cls
|
||||
if (text != null) n.textContent = text
|
||||
return n
|
||||
}
|
||||
var same = function (a, b) { return JSON.stringify(a) === JSON.stringify(b) }
|
||||
var dirty = function () { return !same(draft, saved) }
|
||||
function fill(o) {
|
||||
var r = Object.assign({}, DEFAULTS, o && typeof o === "object" ? o : {})
|
||||
r.channels = (Array.isArray(r.channels) ? r.channels : r.channels ? [r.channels] : []).filter(function (c) { return c && typeof c === "object" }).map(function (c) { return Object.assign({}, c) })
|
||||
r.agents = Array.isArray(r.agents) ? r.agents.map(String) : typeof r.agents === "string" && r.agents ? r.agents.split(",").map(function (s) { return s.trim() }).filter(Boolean) : []
|
||||
return r
|
||||
}
|
||||
function change() { note = ["", false]; renderBar() }
|
||||
|
||||
function toggle(on, label, fn) {
|
||||
var b = el("button", "switch")
|
||||
b.type = "button"
|
||||
b.setAttribute("role", "switch")
|
||||
b.setAttribute("aria-checked", on ? "true" : "false")
|
||||
b.setAttribute("aria-label", label)
|
||||
b.addEventListener("click", function () {
|
||||
var next = b.getAttribute("aria-checked") !== "true"
|
||||
b.setAttribute("aria-checked", next ? "true" : "false")
|
||||
fn(next)
|
||||
})
|
||||
return b
|
||||
}
|
||||
|
||||
// the app's own menu, not a native select
|
||||
function menu(label, items, current, pick) {
|
||||
var wrap = el("div", "menu")
|
||||
var btn = el("button", "", label)
|
||||
btn.type = "button"
|
||||
btn.setAttribute("aria-haspopup", "listbox")
|
||||
var pop = el("div", "pop")
|
||||
pop.hidden = true
|
||||
pop.setAttribute("role", "listbox")
|
||||
items.forEach(function (it) {
|
||||
var o = el("button", "", it[1])
|
||||
o.type = "button"
|
||||
o.setAttribute("role", "option")
|
||||
o.setAttribute("aria-selected", it[0] === current ? "true" : "false")
|
||||
o.addEventListener("click", function () { close(); pick(it[0]) })
|
||||
pop.appendChild(o)
|
||||
})
|
||||
function close() { pop.hidden = true; btn.setAttribute("aria-expanded", "false"); if (openMenu === close) openMenu = null }
|
||||
btn.addEventListener("click", function (e) {
|
||||
e.stopPropagation()
|
||||
var was = pop.hidden
|
||||
if (openMenu) openMenu()
|
||||
if (was) { pop.hidden = false; btn.setAttribute("aria-expanded", "true"); openMenu = close }
|
||||
})
|
||||
wrap.append(btn, pop)
|
||||
return wrap
|
||||
}
|
||||
document.addEventListener("click", function () { if (openMenu) openMenu() })
|
||||
document.addEventListener("keydown", function (e) { if (e.key === "Escape" && openMenu) openMenu() })
|
||||
|
||||
function numberRow(label, key) {
|
||||
var row = el("div", "row")
|
||||
var l = el("label", "", t(label))
|
||||
var i = el("input")
|
||||
i.type = "number"; i.min = "0"; i.value = String(draft[key])
|
||||
i.addEventListener("input", function () { draft[key] = Math.max(0, Number(i.value) || 0); change() })
|
||||
row.append(l, i)
|
||||
return row
|
||||
}
|
||||
function switchRow(label, key) {
|
||||
var row = el("div", "row")
|
||||
row.append(el("span", "name", t(label)), toggle(draft[key] !== false && !!draft[key], t(label), function (v) { draft[key] = v; change() }))
|
||||
return row
|
||||
}
|
||||
|
||||
function missing(c) {
|
||||
var k = KINDS[c.type]
|
||||
return !k || k.fields.some(function (f) { return f[3] && (c[f[0]] == null || String(c[f[0]]).trim() === "") })
|
||||
}
|
||||
|
||||
function channel(c, i) {
|
||||
var k = KINDS[c.type]
|
||||
var box = el("div", "box chan" + (c.off ? " paused" : ""))
|
||||
var head = el("div", "chan-head")
|
||||
head.appendChild(el("span", "title", k ? t(k.name) : String(c.type || "?")))
|
||||
if (!c.off && missing(c)) head.appendChild(el("span", "warn", t("Incomplete, skipped")))
|
||||
var rm = el("button", "quiet", t("Remove"))
|
||||
rm.type = "button"
|
||||
rm.addEventListener("click", function () { draft.channels.splice(i, 1); change(); render() })
|
||||
head.append(toggle(!c.off, t("Sending"), function (v) { if (v) delete c.off; else c.off = true; box.classList.toggle("paused", !v); change() }), rm)
|
||||
box.appendChild(head)
|
||||
if (k) {
|
||||
var fields = el("div", "fields")
|
||||
k.fields.forEach(function (f) {
|
||||
var id = "c" + i + f[0]
|
||||
var lab = el("label", "", t(f[1]))
|
||||
lab.htmlFor = id
|
||||
var inp = el("input")
|
||||
inp.id = id
|
||||
inp.type = f[2] === "secret" ? "password" : f[2] === "number" ? "number" : "text"
|
||||
inp.autocomplete = "off"
|
||||
inp.spellcheck = false
|
||||
inp.value = c[f[0]] == null ? "" : String(c[f[0]])
|
||||
inp.addEventListener("input", function () {
|
||||
var v = inp.value.trim()
|
||||
if (v === "") delete c[f[0]]
|
||||
else if (f[2] === "number" || (f[0] === "chatId" && /^-?\d+$/.test(v))) c[f[0]] = Number(v)
|
||||
else c[f[0]] = v
|
||||
change()
|
||||
})
|
||||
fields.append(lab, inp)
|
||||
})
|
||||
box.appendChild(fields)
|
||||
}
|
||||
return box
|
||||
}
|
||||
|
||||
var bar = el("div", "bar")
|
||||
function renderBar() {
|
||||
bar.textContent = ""
|
||||
var d = dirty()
|
||||
var s = el("span", "status" + (note[1] ? " error" : ""), note[0] || (d ? t("Unsaved changes") : ""))
|
||||
var b = el("button", "primary", t("Save"))
|
||||
b.type = "button"
|
||||
b.disabled = !d || busy
|
||||
b.addEventListener("click", function () { save(draft, true) })
|
||||
bar.append(s, b)
|
||||
}
|
||||
|
||||
function save(next, full) {
|
||||
busy = true; renderBar()
|
||||
return window.magpie.options.set(next).then(function (got) {
|
||||
saved = fill(got)
|
||||
if (full) draft = fill(got)
|
||||
note = [t("Saved"), false]
|
||||
}).catch(function () {
|
||||
note = [t("Could not save"), true]
|
||||
}).then(function () { busy = false; if (full) render(); else renderBar() })
|
||||
}
|
||||
|
||||
function render() {
|
||||
root.textContent = ""
|
||||
var head = el("header")
|
||||
head.appendChild(el("h1", "", t("Notify")))
|
||||
head.appendChild(toggle(draft.enabled !== false, t("Notifications on"), function (v) {
|
||||
// the switch saves at once, and only itself
|
||||
draft.enabled = v
|
||||
save(Object.assign({}, saved, { enabled: v }), false)
|
||||
}))
|
||||
root.appendChild(head)
|
||||
|
||||
var ch = el("section")
|
||||
var h = el("div", "head")
|
||||
h.appendChild(el("h2", "", t("Channels")))
|
||||
h.appendChild(menu(t("Add channel"), Object.keys(KINDS).map(function (k) { return [k, t(KINDS[k].name)] }), "", function (kind) {
|
||||
draft.channels.push({ type: kind }); change(); render()
|
||||
}))
|
||||
ch.appendChild(h)
|
||||
if (!draft.channels.length) ch.appendChild(el("div", "box empty", t("No channel yet. Nothing is sent.")))
|
||||
draft.channels.forEach(function (c, i) { ch.appendChild(channel(c, i)) })
|
||||
root.appendChild(ch)
|
||||
|
||||
var w = el("section")
|
||||
w.appendChild(el("div", "head")).appendChild(el("h2", "", t("When to send")))
|
||||
var box = el("div", "box")
|
||||
box.appendChild(numberRow("Only turns longer than (minutes)", "minMinutes"))
|
||||
box.appendChild(numberRow("One push per conversation every (seconds)", "cooldownSeconds"))
|
||||
box.appendChild(switchRow("Turns that end in an error", "errors"))
|
||||
box.appendChild(switchRow("Account needs signing in again", "accounts"))
|
||||
box.appendChild(switchRow("Include the start of the reply", "includeText"))
|
||||
box.appendChild(switchRow("Also gateway-key and remote requests", "allOrigins"))
|
||||
var ag = el("div", "row")
|
||||
var al = el("label", "", t("Only these agents (ids, comma separated)"))
|
||||
var ai = el("input"); ai.type = "text"; ai.placeholder = "claude, codex"; ai.style.maxWidth = "200px"; ai.spellcheck = false
|
||||
ai.value = draft.agents.join(", ")
|
||||
ai.addEventListener("input", function () { draft.agents = ai.value.split(",").map(function (s) { return s.trim() }).filter(Boolean); change() })
|
||||
ag.append(al, ai)
|
||||
box.appendChild(ag)
|
||||
var lr = el("div", "row")
|
||||
lr.appendChild(el("span", "name", t("Language of the push")))
|
||||
lr.appendChild(menu(LANGS.filter(function (l) { return l[0] === draft.lang })[0] ? LANGS.filter(function (l) { return l[0] === draft.lang })[0][1] : draft.lang, LANGS, draft.lang, function (v) { draft.lang = v; change(); render() }))
|
||||
box.appendChild(lr)
|
||||
w.appendChild(box)
|
||||
root.appendChild(w)
|
||||
|
||||
root.appendChild(bar)
|
||||
renderBar()
|
||||
}
|
||||
|
||||
window.NotifyI18n.onChange(function () { if (draft) render() })
|
||||
window.magpie.ready.then(function () { return window.magpie.options.get() }).then(function (o) {
|
||||
saved = fill(o); draft = fill(o); render()
|
||||
}).catch(function () {
|
||||
root.textContent = t("Could not read the settings")
|
||||
})
|
||||
})()
|
||||
@@ -0,0 +1,61 @@
|
||||
// English source strings; the window's language (magpie.theme.lang) picks
|
||||
// zh, zh-TW, ja or de. A string with no entry shows in English.
|
||||
(function () {
|
||||
"use strict"
|
||||
var T = {
|
||||
"Notify": { zh: "通知", "zh-TW": "通知", ja: "通知", de: "Benachrichtigungen" },
|
||||
"Notifications on": { zh: "开启通知", "zh-TW": "開啟通知", ja: "通知をオン", de: "Benachrichtigungen an" },
|
||||
"Channels": { zh: "渠道", "zh-TW": "管道", ja: "チャンネル", de: "Kanäle" },
|
||||
"Add channel": { zh: "添加渠道", "zh-TW": "新增管道", ja: "チャンネルを追加", de: "Kanal hinzufügen" },
|
||||
"No channel yet. Nothing is sent.": { zh: "还没有渠道,不会发送任何推送。", "zh-TW": "還沒有管道,不會發送任何推播。", ja: "チャンネルがありません。何も送信されません。", de: "Noch kein Kanal. Es wird nichts gesendet." },
|
||||
"Remove": { zh: "删除", "zh-TW": "刪除", ja: "削除", de: "Entfernen" },
|
||||
"Sending": { zh: "发送", "zh-TW": "發送", ja: "送信", de: "Senden" },
|
||||
"Incomplete, skipped": { zh: "未填完整,已跳过", "zh-TW": "未填完整,已略過", ja: "未入力のためスキップ", de: "Unvollständig, übersprungen" },
|
||||
"When to send": { zh: "何时推送", "zh-TW": "何時推播", ja: "送信する条件", de: "Wann senden" },
|
||||
"Only turns longer than (minutes)": { zh: "只推送超过(分钟)的任务", "zh-TW": "只推播超過(分鐘)的任務", ja: "この時間(分)を超えたターンのみ", de: "Nur Durchläufe länger als (Minuten)" },
|
||||
"One push per conversation every (seconds)": { zh: "同一会话推送间隔(秒)", "zh-TW": "同一對話推播間隔(秒)", ja: "同じ会話への送信間隔(秒)", de: "Eine Meldung je Unterhaltung alle (Sekunden)" },
|
||||
"Turns that end in an error": { zh: "出错结束的任务", "zh-TW": "出錯結束的任務", ja: "エラーで終わったターン", de: "Durchläufe, die mit Fehler enden" },
|
||||
"Account needs signing in again": { zh: "账号需要重新登录", "zh-TW": "帳號需要重新登入", ja: "アカウントの再サインインが必要", de: "Konto muss neu angemeldet werden" },
|
||||
"Include the start of the reply": { zh: "附上回复开头", "zh-TW": "附上回覆開頭", ja: "返信の冒頭を含める", de: "Anfang der Antwort anhängen" },
|
||||
"Also gateway-key and remote requests": { zh: "也包括网关密钥和远程设备的请求", "zh-TW": "也包括閘道金鑰和遠端裝置的請求", ja: "ゲートウェイキーとリモートのリクエストも対象", de: "Auch Gateway-Key- und Remote-Anfragen" },
|
||||
"Only these agents (ids, comma separated)": { zh: "只限这些 agent(id,逗号分隔,留空为全部)", "zh-TW": "只限這些 agent(id,逗號分隔,留空為全部)", ja: "対象 agent(id をカンマ区切り、空欄は全て)", de: "Nur diese Agents (IDs, kommagetrennt, leer: alle)" },
|
||||
"Language of the push": { zh: "推送语言", "zh-TW": "推播語言", ja: "通知の言語", de: "Sprache der Meldung" },
|
||||
"Save": { zh: "保存", "zh-TW": "儲存", ja: "保存", de: "Speichern" },
|
||||
"Saved": { zh: "已保存", "zh-TW": "已儲存", ja: "保存しました", de: "Gespeichert" },
|
||||
"Unsaved changes": { zh: "有未保存的更改", "zh-TW": "有未儲存的變更", ja: "未保存の変更があります", de: "Ungespeicherte Änderungen" },
|
||||
"Could not save": { zh: "保存失败", "zh-TW": "儲存失敗", ja: "保存できませんでした", de: "Speichern fehlgeschlagen" },
|
||||
"Could not read the settings": { zh: "读取设置失败", "zh-TW": "讀取設定失敗", ja: "設定を読み込めませんでした", de: "Einstellungen nicht lesbar" },
|
||||
"Topic": { zh: "主题", "zh-TW": "主題", ja: "トピック", de: "Topic" },
|
||||
"Server": { zh: "服务器", "zh-TW": "伺服器", ja: "サーバー", de: "Server" },
|
||||
"Token": { zh: "令牌", "zh-TW": "權杖", ja: "トークン", de: "Token" },
|
||||
"Key": { zh: "密钥", "zh-TW": "金鑰", ja: "キー", de: "Schlüssel" },
|
||||
"Secret": { zh: "签名密钥", "zh-TW": "簽名金鑰", ja: "署名シークレット", de: "Secret" },
|
||||
"Group": { zh: "分组", "zh-TW": "群組", ja: "グループ", de: "Gruppe" },
|
||||
"Sound": { zh: "铃声", "zh-TW": "鈴聲", ja: "サウンド", de: "Ton" },
|
||||
"Priority": { zh: "优先级", "zh-TW": "優先順序", ja: "優先度", de: "Priorität" },
|
||||
"Chat ID": { zh: "聊天 ID", "zh-TW": "聊天 ID", ja: "チャット ID", de: "Chat-ID" },
|
||||
"Webhook URL": { zh: "Webhook 地址", "zh-TW": "Webhook 位址", ja: "Webhook URL", de: "Webhook-URL" },
|
||||
"Custom webhook": { zh: "自定义 webhook", "zh-TW": "自訂 webhook", ja: "カスタム webhook", de: "Eigener Webhook" },
|
||||
"Server酱": { ja: "Server酱", de: "Server酱" },
|
||||
"Feishu": { zh: "飞书", "zh-TW": "飛書", ja: "Feishu", de: "Feishu" },
|
||||
"DingTalk": { zh: "钉钉", "zh-TW": "釘釘", ja: "DingTalk", de: "DingTalk" },
|
||||
"WeCom": { zh: "企业微信", "zh-TW": "企業微信", ja: "WeCom", de: "WeCom" }
|
||||
}
|
||||
var lang = "en"
|
||||
var listeners = []
|
||||
function t(s) { var e = T[s]; return (e && e[lang]) || s }
|
||||
function apply(theme) {
|
||||
var l = theme && theme.lang
|
||||
lang = l === "zh" || l === "zh-TW" || l === "ja" || l === "de" ? l : "en"
|
||||
document.documentElement.lang = lang
|
||||
document.title = t("Notify")
|
||||
listeners.forEach(function (f) { f() })
|
||||
}
|
||||
window.NotifyI18n = { t: t, onChange: function (f) { listeners.push(f) } }
|
||||
var m = window.magpie
|
||||
if (m) {
|
||||
apply(m.theme)
|
||||
if (m.ready) m.ready.then(apply).catch(function () {})
|
||||
if (m.onTheme) m.onTheme(apply)
|
||||
}
|
||||
})()
|
||||
@@ -0,0 +1,15 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Notify</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<main id="root"></main>
|
||||
<script src="_magpie/bridge.js"></script>
|
||||
<script src="i18n.js"></script>
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,56 @@
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
--bg: var(--magpie-bg, #f6f6f5);
|
||||
--card: var(--magpie-card, #ffffff);
|
||||
--fg: var(--magpie-fg, #1d1d1f);
|
||||
--muted: var(--magpie-muted, #6e6e73);
|
||||
--line: var(--magpie-line, #dcdcdc);
|
||||
--accent: var(--magpie-accent, #3a5f8f);
|
||||
--soft: var(--magpie-accent-soft, #e8eef5);
|
||||
--red: var(--magpie-red, #b3402f);
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body { margin: 0; background: var(--bg); color: var(--fg); font: 13px/1.45 var(--magpie-font, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif); }
|
||||
main { max-width: 720px; margin: 0 auto; padding: 24px 20px 56px; }
|
||||
header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
|
||||
h1 { font-size: 20px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
|
||||
h2 { font-size: 13px; font-weight: 600; margin: 0; }
|
||||
section { margin-bottom: 24px; }
|
||||
.head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
|
||||
.box { background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
|
||||
.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 9px 12px; min-height: 40px; }
|
||||
.row + .row, .fields { border-top: 1px solid var(--line); }
|
||||
.row > label, .row > .name { flex: 1 1 auto; min-width: 0; }
|
||||
.chan + .chan { margin-top: 8px; }
|
||||
.chan-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
|
||||
.chan-head .title { font-weight: 600; flex: 1; }
|
||||
.chan.paused .title, .chan.paused .fields { opacity: .55; }
|
||||
.fields { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; padding: 10px 12px; align-items: center; }
|
||||
.fields label { color: var(--muted); }
|
||||
.warn { color: var(--red); font-size: 12px; }
|
||||
input[type=text], input[type=password], input[type=number] { width: 100%; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font: inherit; color: inherit; }
|
||||
input[type=number] { width: 90px; text-align: right; }
|
||||
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
|
||||
button { font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 3px 10px; cursor: pointer; transition: border-color .15s ease, transform .12s cubic-bezier(.23,1,.32,1); }
|
||||
button:active:not(:disabled) { transform: scale(.97); }
|
||||
@media (hover: hover) and (pointer: fine) { button:hover:not(:disabled) { border-color: var(--muted); } }
|
||||
button:disabled { opacity: .5; cursor: default; }
|
||||
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
|
||||
button.quiet { border-color: transparent; background: transparent; color: var(--muted); }
|
||||
.switch { position: relative; width: 34px; height: 20px; padding: 0; border-radius: 10px; background: var(--line); border: 0; flex: none; transition: background .15s ease; }
|
||||
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .18s cubic-bezier(.23,1,.32,1); }
|
||||
.switch[aria-checked=true] { background: var(--accent); }
|
||||
.switch[aria-checked=true]::after { transform: translateX(14px); }
|
||||
.menu { position: relative; display: inline-block; }
|
||||
.menu > button::after { content: " \25BE"; color: var(--muted); }
|
||||
.pop { position: absolute; right: 0; top: calc(100% + 4px); z-index: 5; min-width: 150px; max-height: 280px; overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 4px; box-shadow: 0 6px 20px rgba(0,0,0,.14); transform-origin: top right; animation: pop .15s cubic-bezier(.23,1,.32,1); }
|
||||
.pop[hidden] { display: none; }
|
||||
.pop button { display: block; width: 100%; text-align: left; border: 0; background: transparent; border-radius: 5px; padding: 5px 8px; }
|
||||
.pop button[aria-selected=true] { background: var(--soft); color: var(--accent); }
|
||||
@keyframes pop { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: none; } }
|
||||
.bar { position: sticky; bottom: 0; display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 10px 0; background: var(--bg); }
|
||||
.status { color: var(--muted); }
|
||||
.status.error { color: var(--red); }
|
||||
.empty { padding: 14px 12px; color: var(--muted); }
|
||||
@media (max-width: 480px) { .fields { grid-template-columns: 1fr; gap: 4px; } }
|
||||
@media (prefers-reduced-motion: reduce) { .pop { animation: none; } .switch::after { transition: none; } }
|
||||
Reference in New Issue
Block a user