Paskelbtas šaltinis
Atsisiųsti šaltinį ZIP
CH-J Tools
Naršyti aplankus ir failus konkrečiai programai išleisti.
CH-J / Server Manager
1704 failai
0.1.2-beta
Pridėta: · Pastatytas:
1
"use strict";2
// Texts: i18n/license/<language>.json, languages: i18n/languages.json (injected by the Rust Core).3
// The license itself is never translated; the operational guidance exists in CS/DE/EN only.4
const i18nData = globalThis.__CHJ_I18N__ || { manifest: { languages: [] }, catalogs: { license: {} } };5
const fallbackCopy = i18nData.catalogs.license.en || i18nData.catalogs.license.cs || {};6
const copy = new Proxy(i18nData.catalogs.license, { get: (target, language) => ({ ...fallbackCopy, ...(target[language] || {}) }) });7
const knownLanguage = language => Boolean(i18nData.catalogs.license[language]);8
const el = id => document.getElementById(id);9
for (const language of i18nData.manifest.languages || []) {10
if (!knownLanguage(language.code)) continue;11
const option = document.createElement("option");12
option.value = language.code;13
option.textContent = language.name;14
el("language").append(option);15
}16
let license;17
let showingLicense = false;18
// The guidance documents use a small Markdown subset (#, ##, **bold**, "- " lists, ---, two trailing spaces for a19
// line break). It is rendered with DOM nodes only, never as HTML, so the text cannot inject markup.20
function inline(parent, text) {21
text.split(/(\*\*[^*]+\*\*)/).forEach(part => {22
if (part.startsWith("**") && part.endsWith("**") && part.length > 4) {23
const strong = document.createElement("strong");24
strong.textContent = part.slice(2, -2);25
parent.append(strong);26
} else if (part) parent.append(part);27
});28
}29
function renderGuidance(container, markdown) {30
container.replaceChildren();31
let list = null;32
let paragraph = null;33
const close = () => { list = null; paragraph = null; };34
for (const raw of markdown.replace(/\r\n?/g, "\n").split("\n")) {35
const line = raw.trimEnd();36
const hardBreak = raw.endsWith(" ");37
if (!line.trim()) { close(); continue; }38
const heading = /^(#{1,2})\s+(.*)$/.exec(line);39
if (heading) {40
close();41
const node = document.createElement(heading[1].length === 1 ? "h2" : "h3");42
inline(node, heading[2]);43
container.append(node);44
} else if (/^-{3,}$/.test(line.trim())) {45
close();46
container.append(document.createElement("hr"));47
} else if (/^[-*]\s+/.test(line)) {48
paragraph = null;49
if (!list) { list = document.createElement("ul"); container.append(list); }50
const item = document.createElement("li");51
inline(item, line.replace(/^[-*]\s+/, ""));52
list.append(item);53
} else if (list && /^\s+/.test(raw)) {54
list.lastChild.append(" ");55
inline(list.lastChild, line.trim());56
} else {57
list = null;58
if (!paragraph) { paragraph = document.createElement("p"); container.append(paragraph); }59
else if (!paragraph.lastChild || paragraph.lastChild.nodeName !== "BR") paragraph.append(" ");60
inline(paragraph, line.trim());61
if (hardBreak) paragraph.append(document.createElement("br"));62
}63
}64
}65
function translate() {66
const language = el("language").value;67
const text = copy[language];68
document.documentElement.lang = language;69
for (const [id, key] of [["consentLicense", "consent"], ["consentRisk", "risk"], ["accept", "accept"], ["decline", "decline"], ["continue", "next"], ["back", "back"]]) el(id).textContent = text[key];70
el("heading").textContent = text[showingLicense ? "heading" : "guidanceHeading"];71
el("intro").textContent = text[showingLicense ? "intro" : "guidanceIntro"];72
renderGuidance(el("guidanceText"), license?.guidance[language] || license?.guidance.en || "");73
el("guidanceText").setAttribute("aria-label", text.guidanceHeading);74
el("guidanceText").hidden = showingLicense;75
for (const id of ["licenseText", "consentRow", "accept", "back"]) el(id).hidden = !showingLicense;76
el("continue").hidden = showingLicense;77
el("continue").disabled = !license;78
}79
el("language").addEventListener("change", translate);80
el("consent").addEventListener("change", () => { el("accept").disabled = !license || !showingLicense || !el("consent").checked; });81
el("decline").addEventListener("click", () => window.licenseApi.decline());82
el("continue").addEventListener("click", async () => {83
if (!license) return;84
el("continue").disabled = true;85
try {86
await window.licenseApi.showLicense({ guidanceSha256: license.guidanceSha256 });87
showingLicense = true;88
el("error").textContent = "";89
translate();90
el("licenseText").focus();91
} catch { el("error").textContent = copy[el("language").value].error; el("continue").disabled = false; }92
});93
el("back").addEventListener("click", () => {94
showingLicense = false;95
el("consent").checked = false;96
el("accept").disabled = true;97
translate();98
});99
el("accept").addEventListener("click", async () => {100
if (!license || !showingLicense || !el("consent").checked) return;101
el("accept").disabled = true;102
try { await window.licenseApi.accept({ accepted: true, sha256: license.sha256, guidanceSha256: license.guidanceSha256 }); }103
catch { el("error").textContent = copy[el("language").value].error; el("accept").disabled = !el("consent").checked; }104
});105
translate();106
window.licenseApi.read().then(value => {107
license = value;108
// The license and the safety guidance exist only in Czech, German and English (never translated further):109
// another UI language shows them in its base language when available, otherwise in English.110
const base = String(value.language || "").split("-")[0];111
el("language").value = knownLanguage(value.language) ? value.language : knownLanguage(base) ? base : value.language && knownLanguage("en") ? "en" : (knownLanguage("cs") ? "cs" : "en");112
el("licenseText").textContent = value.text;113
el("release").textContent = `CH-J Proprietary Software License ${value.licenseVersion} · v${value.appVersion} · ${value.buildId}`;114
translate();115
}).catch(() => { el("error").textContent = copy[el("language").value].error; });SHA-256
bb0c67c5297bb292ba9ea2c4e67f660b105080f2d8edc868861aa92fcd2a47c7CH-J Proprietary Software License 1.14 · Šaltinis pateiktas pagal CH-J Proprietary Software License 1.14. Jo prieinamumas nekeičia licencijos sąlygų ir nesuteikia papildomų teisių.
Archyvas SHA-256
ac8fe790f4ba60fc098f8c985fc2656cfcc6cdc21fb34b30e308a2b54e62258f