提交 Haven Android 仓库源码 v5.87.79

This commit is contained in:
ali
2026-09-10 13:45:36 +08:00
parent 87b452c4dc
commit 22f4ca5830
2524 changed files with 599455 additions and 1 deletions
File diff suppressed because it is too large Load Diff
+54
View File
@@ -0,0 +1,54 @@
/* Translation contribution page — scoped .tr-* so it rides on top of the
Jekyll cayman theme without fighting it. Vanilla, no framework. */
/* `display:flex` below (modal, progress, filters) outweighs the UA
[hidden]{display:none}, so the attribute would never hide them — pin it. */
[hidden] { display: none !important; }
.tr-intro { color: #444; }
.tr-controls { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin: 1rem 0 .5rem; }
.tr-controls select, .tr-controls input { font-size: 1rem; padding: .35rem .5rem; }
.tr-progress { display: flex; align-items: center; gap: .75rem; margin: .25rem 0 1rem; }
.tr-bar { flex: 1; height: 12px; background: #e7e7e7; border-radius: 6px; overflow: hidden; max-width: 420px; }
.tr-bar-fill { height: 100%; background: #2a7ae2; width: 0; transition: width .2s; }
.tr-progress span { font-variant-numeric: tabular-nums; color: #555; font-size: .9rem; }
.tr-filters { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin: .5rem 0 1rem; padding: .75rem; background: #f6f8fa; border-radius: 6px; }
.tr-filters input[type=search] { flex: 1; min-width: 200px; padding: .4rem .6rem; font-size: 1rem; }
.tr-check { white-space: nowrap; }
.tr-status { color: #777; padding: 1rem 0; }
.tr-modhead { margin: 1.5rem 0 .25rem; padding-bottom: .2rem; border-bottom: 2px solid #eee; display: flex; align-items: baseline; gap: .6rem; }
.tr-modhead code { font-size: 1rem; font-weight: 600; color: #24292e; }
.tr-modhead .tr-modpct { font-size: .82rem; color: #777; font-variant-numeric: tabular-nums; }
.tr-context { margin: .8rem 0 .2rem; font-style: italic; color: #6a737d; font-size: .9rem; }
.tr-row { padding: .5rem .6rem; border-radius: 6px; margin: .2rem 0; }
.tr-row:hover { background: #fafbfc; }
.tr-row.tr-changed { background: #fffbdd; }
.tr-meta { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.tr-name { font-size: .8rem; color: #6f42c1; background: #f3effa; padding: .05rem .35rem; border-radius: 4px; }
.tr-arg { font-size: .72rem; font-family: monospace; color: #b35900; background: #fff3e0; padding: .05rem .3rem; border-radius: 4px; }
.tr-en { margin: .25rem 0; color: #111; }
.tr-input { width: 100%; box-sizing: border-box; font-size: 1rem; padding: .4rem .55rem; border: 1px solid #ccd0d4; border-radius: 5px; font-family: inherit; }
.tr-input:focus { border-color: #2a7ae2; outline: none; }
textarea.tr-input { min-height: 2.4rem; resize: vertical; }
.tr-actionbar { position: sticky; bottom: 0; padding: .75rem 0; background: linear-gradient(180deg, rgba(255,255,255,0) 0%, #fff 35%); text-align: right; }
.tr-actionbar button { font-size: 1rem; padding: .55rem 1.1rem; background: #2a7ae2; color: #fff; border: 0; border-radius: 6px; cursor: pointer; }
.tr-actionbar button:disabled { background: #b8c4d0; cursor: default; }
.tr-modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 3vh 1rem; z-index: 1000; overflow: auto; }
.tr-modal-box { background: #fff; border-radius: 8px; padding: 1.25rem 1.5rem; max-width: 820px; width: 100%; position: relative; }
.tr-modal-close { position: absolute; top: .5rem; right: .75rem; font-size: 1.5rem; line-height: 1; background: none; border: 0; cursor: pointer; color: #888; }
.tr-modal-help { color: #444; font-size: .95rem; }
.tr-modal-help ol { margin: .4rem 0 0 1.1rem; }
.tr-card { margin: 1rem 0; padding: .8rem; border: 1px solid #e1e4e8; border-radius: 6px; }
.tr-card h3 { margin: 0 0 .4rem; font-size: .9rem; }
.tr-out { width: 100%; box-sizing: border-box; font-family: monospace; font-size: .8rem; white-space: pre; overflow: auto; }
.tr-card-actions { display: flex; gap: .6rem; margin-top: .5rem; align-items: center; }
.tr-copy { padding: .35rem .8rem; cursor: pointer; border: 1px solid #ccc; border-radius: 5px; background: #f6f8fa; }
.tr-open { padding: .35rem .9rem; background: #2a7ae2; color: #fff; border-radius: 5px; text-decoration: none; }
+333
View File
@@ -0,0 +1,333 @@
/* Haven translation contribution page.
* Browses docs/i18n/strings.json and hands off edits to GitHub's own
* editor / fork / PR flow (GitHub does the auth). No backend, no secrets.
* Vanilla JS — the Pages site has no bundler. */
(function () {
"use strict";
var REPO = "GlassHaven/Haven", BRANCH = "main", RENDER_CAP = 800;
var LOCALE_NAMES = {
ar: "Arabic · العربية", bn: "Bengali · বাংলা", de: "German · Deutsch",
es: "Spanish · Español", fr: "French · Français", hi: "Hindi · हिन्दी",
ja: "Japanese · 日本語", ko: "Korean · 한국어", pt: "Portuguese · Português",
ru: "Russian · Русский", sr: "Serbian · српски",
zh: "Chinese (Simplified) · 简体中文"
};
var data = null; // the fetched JSON
var total = 0; // total source strings
var index = {}; // module -> { name -> stringObj }
var edits = {}; // code -> { module -> { name -> value } }
// ---------- tiny DOM helper ----------
function el(tag, props, kids) {
var n = document.createElement(tag);
if (props) for (var k in props) {
if (k === "class") n.className = props[k];
else if (k === "text") n.textContent = props[k];
else if (k in n) n[k] = props[k];
else n.setAttribute(k, props[k]);
}
(kids || []).forEach(function (c) {
if (c != null) n.appendChild(typeof c === "string" ? document.createTextNode(c) : c);
});
return n;
}
function $(id) { return document.getElementById(id); }
// ---------- Android string value codec ----------
function decode(s) {
return s.replace(/\\n/g, "\n").replace(/\\t/g, "\t")
.replace(/\\'/g, "'").replace(/\\"/g, '"')
.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
}
function escapeAndroid(s) {
var v = s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")
.replace(/'/g, "\\'").replace(/"/g, '\\"')
.replace(/\n/g, "\\n").replace(/\t/g, "\\t");
if (/^\s|\s$/.test(s)) v = '"' + v + '"'; // preserve edge whitespace
return v;
}
function escapeRegex(s) { return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); }
// ---------- locale state ----------
function localeOf() {
var sel = $("tr-locale").value;
if (sel === "__new__") return ($("tr-newcode").value || "").trim();
return sel;
}
function isNewLocale(code) { return !data.locales.includes(code); }
function completeness(code) {
if (!code || isNewLocale(code)) return { done: 0, total: total };
var done = 0;
data.modules.forEach(function (m) {
m.strings.forEach(function (s) { if (code in s.t) done++; });
});
return { done: done, total: total };
}
function moduleCompleteness(m, code) {
if (isNewLocale(code)) return { done: 0, total: m.strings.length };
var done = 0;
m.strings.forEach(function (s) { if (code in s.t) done++; });
return { done: done, total: m.strings.length };
}
// ---------- edits ----------
function originalDecoded(module, name, code) {
var s = index[module][name];
return decode((s.t && s.t[code]) || "");
}
function currentValue(module, name, code) {
var e = edits[code] && edits[code][module];
if (e && name in e) return e[name];
return originalDecoded(module, name, code);
}
function onEdit(module, name, code, value, row) {
if (!code) return;
var orig = originalDecoded(module, name, code);
edits[code] = edits[code] || {};
edits[code][module] = edits[code][module] || {};
if (value === orig) {
delete edits[code][module][name];
if (!Object.keys(edits[code][module]).length) delete edits[code][module];
row.classList.remove("tr-changed");
} else {
edits[code][module][name] = value;
row.classList.add("tr-changed");
}
updateCounter();
}
function countChanges(code) {
var e = edits[code]; if (!e) return 0;
var n = 0; for (var m in e) n += Object.keys(e[m]).length;
return n;
}
function updateCounter() {
var code = localeOf(), n = countChanges(code), btn = $("tr-propose");
btn.textContent = "Propose " + n + " change" + (n === 1 ? "" : "s");
btn.disabled = n === 0 || !code;
}
// ---------- filtering ----------
function isUntranslated(s, code) { return isNewLocale(code) || !(code in s.t); }
function matches(s, module, q) {
if (!q) return true;
return s.name.toLowerCase().indexOf(q) >= 0 ||
decode(s.en).toLowerCase().indexOf(q) >= 0 ||
module.toLowerCase().indexOf(q) >= 0;
}
// ---------- rendering ----------
function buildRow(module, s, code) {
var multiline = decode(s.en).length > 42;
var input = el(multiline ? "textarea" : "input",
{ class: "tr-input", value: currentValue(module, s.name, code) });
if (code && code.indexOf("ar") === 0) input.dir = "rtl";
var meta = el("div", { class: "tr-meta" },
[el("code", { class: "tr-name", text: s.name })].concat(
(s.args || []).map(function (a) { return el("span", { class: "tr-arg", text: a }); })));
var row = el("div", { class: "tr-row" },
[meta, el("div", { class: "tr-en", text: decode(s.en) }), input]);
if (edits[code] && edits[code][module] && (s.name in edits[code][module]))
row.classList.add("tr-changed");
input.addEventListener("input", function () { onEdit(module, s.name, code, input.value, row); });
return row;
}
function render() {
var code = localeOf();
var list = $("tr-list"), status = $("tr-status");
list.textContent = "";
if (!code) { status.textContent = "Pick a language to begin."; status.hidden = false; return; }
var q = ($("tr-search").value || "").trim().toLowerCase();
var modFilter = $("tr-module").value;
var onlyUntr = $("tr-untranslated").checked;
var shown = 0, capped = false;
data.modules.forEach(function (m) {
if (capped) return;
if (modFilter && m.module !== modFilter) return;
var picks = m.strings.filter(function (s) {
return matches(s, m.module, q) && (!onlyUntr || isUntranslated(s, code));
});
if (!picks.length) return;
var mc = moduleCompleteness(m, code);
list.appendChild(el("div", { class: "tr-modhead" }, [
el("code", { text: m.module }),
el("span", { class: "tr-modpct", text: mc.done + " / " + mc.total + " translated" })
]));
var lastComment = null;
for (var i = 0; i < picks.length; i++) {
if (shown >= RENDER_CAP) { capped = true; break; }
var s = picks[i];
if (s.comment && s.comment !== lastComment) {
list.appendChild(el("div", { class: "tr-context", text: s.comment }));
lastComment = s.comment;
}
list.appendChild(buildRow(m.module, s, code));
shown++;
}
});
if (!shown) {
status.textContent = onlyUntr
? "Nothing untranslated here — uncheck “Only untranslated” to revise existing strings."
: "No strings match your filter.";
status.hidden = false;
} else if (capped) {
status.textContent = "Showing the first " + RENDER_CAP +
" strings — use the module filter or search to narrow down.";
status.hidden = false;
} else {
status.hidden = true;
}
}
function updateProgress() {
var code = localeOf(), wrap = $("tr-progress");
if (!code) { wrap.hidden = true; return; }
var c = completeness(code), pct = c.total ? Math.round(100 * c.done / c.total) : 0;
wrap.hidden = false;
$("tr-bar-fill").style.width = pct + "%";
$("tr-progress-label").textContent =
pct + "% — " + c.done + " / " + c.total +
(isNewLocale(code) ? " (new language)" : " translated");
}
// ---------- propose (GitHub handoff) ----------
function patch(text, module, moduleEdits) {
for (var name in moduleEdits) {
var esc = escapeAndroid(moduleEdits[name]);
var re = new RegExp('(<string\\s+name="' + escapeRegex(name) +
'"[^>]*>)([\\s\\S]*?)(</string>)');
if (re.test(text)) {
(function (esc) {
text = text.replace(re, function (m, p1, p2, p3) { return p1 + esc + p3; });
})(esc);
} else {
(function (name, esc) {
text = text.replace(/<\/resources>\s*$/, function () {
return ' <string name="' + name + '">' + esc + '</string>\n</resources>\n';
});
})(name, esc);
}
}
return text;
}
function newFile(moduleEdits) {
var lines = ['<?xml version="1.0" encoding="utf-8"?>', '<resources>'];
for (var name in moduleEdits)
lines.push(' <string name="' + name + '">' + escapeAndroid(moduleEdits[name]) + '</string>');
lines.push('</resources>', '');
return lines.join("\n");
}
function proposeCard(module, code) {
var path = module + "/src/main/res/values-" + code + "/strings.xml";
var card = el("div", { class: "tr-card" }, [el("h3", {}, [el("code", { text: path })])]);
var ta = el("textarea", { class: "tr-out", readonly: true, rows: 12 });
card.appendChild(ta);
var actions = el("div", { class: "tr-card-actions" });
card.appendChild(actions);
function wire(content, url, label) {
ta.value = content;
var copy = el("button", { class: "tr-copy", text: "Copy" });
copy.addEventListener("click", function () {
navigator.clipboard.writeText(content).then(function () {
copy.textContent = "Copied!";
setTimeout(function () { copy.textContent = "Copy"; }, 1500);
});
});
actions.appendChild(copy);
actions.appendChild(el("a", { class: "tr-open", href: url, target: "_blank", rel: "noopener", text: label }));
}
var moduleEdits = edits[code][module];
if (isNewLocale(code)) {
var content = newFile(moduleEdits);
var enc = encodeURIComponent(content);
var base = "https://github.com/" + REPO + "/new/" + BRANCH + "?filename=" + encodeURIComponent(path);
// Prefill only when small enough to fit a URL reliably; else copy-paste.
wire(content, enc.length < 6000 ? base + "&value=" + enc : base, "Create file on GitHub");
} else {
ta.value = "Fetching current file…";
fetch("https://raw.githubusercontent.com/" + REPO + "/" + BRANCH + "/" + path)
.then(function (r) { if (!r.ok) throw new Error(r.status); return r.text(); })
.then(function (raw) {
wire(patch(raw, module, moduleEdits),
"https://github.com/" + REPO + "/edit/" + BRANCH + "/" + path,
"Open in GitHub editor");
})
.catch(function () {
wire("Couldn't fetch the current file. Open it on GitHub and apply your edits by hand:\n" +
JSON.stringify(moduleEdits, null, 2),
"https://github.com/" + REPO + "/edit/" + BRANCH + "/" + path,
"Open in GitHub editor");
});
}
return card;
}
function propose() {
var code = localeOf(); if (!code) return;
var e = edits[code]; if (!e) return;
var mods = Object.keys(e).filter(function (m) { return Object.keys(e[m]).length; });
var body = $("tr-modal-body"); body.textContent = "";
mods.forEach(function (m) { body.appendChild(proposeCard(m, code)); });
$("tr-modal").hidden = false;
}
// ---------- init ----------
function init() {
var sel = $("tr-locale");
sel.appendChild(el("option", { value: "", text: "Select a language…" }));
data.locales.forEach(function (loc) {
sel.appendChild(el("option", { value: loc, text: LOCALE_NAMES[loc] || loc }));
});
sel.appendChild(el("option", { value: "__new__", text: "➕ Add a new language…" }));
var ms = $("tr-module");
data.modules.forEach(function (m) {
ms.appendChild(el("option", { value: m.module, text: m.module }));
});
function onLocaleChange() {
$("tr-newlang").hidden = sel.value !== "__new__";
var code = localeOf();
$("tr-filters").hidden = !code;
$("tr-actionbar").hidden = !code;
updateProgress(); updateCounter(); render();
}
sel.addEventListener("change", onLocaleChange);
$("tr-newcode").addEventListener("input", function () { updateProgress(); updateCounter(); render(); });
$("tr-search").addEventListener("input", render);
$("tr-module").addEventListener("change", render);
$("tr-untranslated").addEventListener("change", render);
$("tr-propose").addEventListener("click", propose);
$("tr-modal-close").addEventListener("click", function () { $("tr-modal").hidden = true; });
$("tr-modal").addEventListener("click", function (ev) { if (ev.target === $("tr-modal")) $("tr-modal").hidden = true; });
$("tr-status").textContent = "Pick a language to begin.";
$("tr-status").hidden = false;
}
fetch("i18n/strings.json")
.then(function (r) { if (!r.ok) throw new Error(r.status); return r.json(); })
.then(function (json) {
data = json;
data.modules.forEach(function (m) {
index[m.module] = {};
m.strings.forEach(function (s) { index[m.module][s.name] = s; total++; });
});
init();
})
.catch(function (err) {
$("tr-status").textContent = "Failed to load strings.json: " + err.message;
});
})();