index.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>PageOS 应用仓库</title>
  7. <link
  8. rel="icon"
  9. type="image/svg+xml"
  10. href="data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDMyIDMyIj4KICA8IS0tIOWkluahhuefqeW9oiAtLT4KICA8cmVjdCB4PSIyIiB5PSIyIiB3aWR0aD0iMjgiIGhlaWdodD0iMjgiIHJ4PSIxMCIgcnk9IjEwIgogICAgZmlsbD0iIzQyNDI0MiIKICAgIHN0cm9rZT0iIzAwNjk1YyIKICAgIHN0cm9rZS13aWR0aD0iNCIvPgoKICA8IS0tIOW3puecvO+8muWwj+WchueCuSAtLT4KICA8Y2lyY2xlIGN4PSIxMiIgY3k9IjE0IiByPSIxLjUiIGZpbGw9IiNmNWY1ZjUiIC8+CgogIDwhLS0g5Y+z55y877ya5bCP5ZyG54K5IC0tPgogIDxjaXJjbGUgY3g9IjIwIiBjeT0iMTQiIHI9IjEuNSIgZmlsbD0iI2Y1ZjVmNSIgLz4KCiAgPCEtLSDpvLvlrZDvvJrnq5bnur8gLS0+CiAgPGxpbmUgeDE9IjE2IiB5MT0iMTYiIHgyPSIxNiIgeTI9IjE4IiBzdHJva2U9IiNmNWY1ZjUiIHN0cm9rZS13aWR0aD0iMS41IiAvPgoKICA8IS0tIOW+rueskeeahOWYtO+8muS4iuaJrOeahOW8p+e6vyAtLT4KICA8cGF0aCBkPSJNIDE0IDIwIFEgMTYgMjIgMTggMjAiIAogICAgICAgIGZpbGw9Im5vbmUiIAogICAgICAgIHN0cm9rZT0iI2Y1ZjVmNSIgCiAgICAgICAgc3Ryb2tlLXdpZHRoPSIxLjUiIAogICAgICAgIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgLz4KPC9zdmc+"
  11. />
  12. <style>
  13. /* 全局样式 */
  14. * {
  15. margin: 0;
  16. padding: 0;
  17. box-sizing: border-box;
  18. text-decoration: none;
  19. color: var(--secondary-font-color);
  20. }
  21. ::selection {
  22. background: var(--accent-bg-color);
  23. color: var(--accent-font-color);
  24. }
  25. body {
  26. font-family: "Maple Mono CN", "Courier New", Courier, monospace;
  27. background: #424242;
  28. height: 100vh;
  29. display: flex;
  30. flex-direction: column;
  31. --accent-color: #64ffda; /* 强调色:边框 */
  32. --secondary-color: #00695c; /* 次要色:未激活边框 */
  33. --danger-color: #ff6d00; /* 着重色:边框 */
  34. --accent-bg-color: #009688;
  35. --secondary-bg-color: #616161;
  36. --content-bg-color: #424242;
  37. --accent-font-color: #f5f5f5;
  38. --secondary-font-color: #eeeeee;
  39. --margin-padding: 0.5rem;
  40. --border-thickness: 0.2rem;
  41. --border-radius: 0.5rem;
  42. --shadow: 0.6rem 0.6rem 0.1rem 0.1rem rgba(0, 0, 0, 0.2);
  43. --focused-bg-color: rgba(255, 255, 255, 0.1);
  44. }
  45. .container {
  46. padding: var(--margin-padding);
  47. flex: 1;
  48. overflow-y: auto;
  49. }
  50. /* 搜索栏样式 */
  51. .search-container {
  52. display: flex;
  53. gap: var(--margin-padding);
  54. background: var(--secondary-bg-color);
  55. padding: var(--margin-padding);
  56. border-bottom: var(--border-thickness) solid var(--secondary-color);
  57. }
  58. .search-box {
  59. transition: all 0.2s ease;
  60. flex: 1;
  61. padding: var(--margin-padding);
  62. border: var(--border-thickness) solid var(--secondary-color);
  63. border-radius: var(--margin-padding);
  64. background: var(--content-bg-color);
  65. font-size: 1rem;
  66. }
  67. .search-box:focus {
  68. --secondary-bg-color: var(--accent-bg-color);
  69. --secondary-font-color: var(--accent-font-color);
  70. --secondary-color: var(--accent-color);
  71. }
  72. .top-buttons {
  73. display: flex;
  74. border: var(--border-thickness) solid var(--secondary-color);
  75. padding: var(--margin-padding);
  76. border-radius: var(--margin-padding);
  77. background: var(--content-bg-color);
  78. position: relative;
  79. }
  80. /* 应用网格样式 */
  81. .apps-grid {
  82. display: grid;
  83. grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  84. gap: calc(2 * var(--margin-padding));
  85. padding: var(--margin-padding) 0;
  86. }
  87. .app-card {
  88. background: var(--secondary-bg-color);
  89. border: var(--border-thickness) solid var(--secondary-color);
  90. border-radius: var(--margin-padding);
  91. padding: var(--margin-padding);
  92. text-align: center;
  93. cursor: pointer;
  94. & > * {
  95. pointer-events: none;
  96. }
  97. }
  98. a {
  99. transition: all 0.2s ease;
  100. }
  101. a:hover {
  102. border-color: var(--accent-color);
  103. }
  104. .app-card:hover {
  105. border-color: var(--accent-color);
  106. transform: scale(1.1);
  107. .app-name {
  108. white-space: initial;
  109. }
  110. }
  111. /* 图标样式 */
  112. .app-icon {
  113. width: 64px;
  114. height: 64px;
  115. margin: 0 auto 0.5rem;
  116. background: var(--content-bg-color);
  117. border-radius: 0.5rem;
  118. display: flex;
  119. align-items: center;
  120. justify-content: center;
  121. font-size: 2rem;
  122. font-weight: bold;
  123. }
  124. /* 应用信息样式 */
  125. .app-name {
  126. font-weight: bold;
  127. margin-bottom: 0.25rem;
  128. white-space: nowrap;
  129. overflow: hidden;
  130. text-overflow: ellipsis;
  131. }
  132. .app-author {
  133. font-size: 0.8rem;
  134. color: #b0b0b0;
  135. }
  136. /* 加载状态 */
  137. .loading {
  138. text-align: center;
  139. padding: 2rem;
  140. font-style: italic;
  141. }
  142. /* 翻译按钮相关 */
  143. .translateSelectLanguage {
  144. background: inherit;
  145. color: inherit;
  146. opacity: 0;
  147. cursor: pointer;
  148. position: absolute;
  149. top: 0;
  150. right: 0;
  151. bottom: 0;
  152. left: 0;
  153. }
  154. </style>
  155. <script
  156. src="https://lib.baomitu.com/translate.js/3.17.0/translate.js"
  157. type="text/javascript"
  158. ></script>
  159. </head>
  160. <body>
  161. <div class="search-container">
  162. <input
  163. type="text"
  164. class="search-box"
  165. placeholder="搜索应用……"
  166. id="searchInput"
  167. />
  168. <a id="translate" class="top-buttons language-selector" title="语言">
  169. <svg
  170. xmlns="http://www.w3.org/2000/svg"
  171. width="24"
  172. height="24"
  173. viewBox="0 0 24 24"
  174. fill="none"
  175. stroke="currentColor"
  176. stroke-width="2"
  177. stroke-linecap="round"
  178. stroke-linejoin="round"
  179. class="icon icon-tabler icons-tabler-outline icon-tabler-world"
  180. >
  181. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  182. <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
  183. <path d="M3.6 9h16.8" />
  184. <path d="M3.6 15h16.8" />
  185. <path d="M11.5 3a17 17 0 0 0 0 18" />
  186. <path d="M12.5 3a17 17 0 0 1 0 18" /></svg
  187. ></a>
  188. <a
  189. href="https://github.com/swaybien/pageos-apps"
  190. target="_blank"
  191. class="top-buttons"
  192. title="仓库"
  193. >
  194. <svg
  195. xmlns="http://www.w3.org/2000/svg"
  196. width="24"
  197. height="24"
  198. viewBox="0 0 24 24"
  199. fill="none"
  200. stroke="currentColor"
  201. stroke-width="2"
  202. stroke-linecap="round"
  203. stroke-linejoin="round"
  204. class="icon icon-tabler icons-tabler-outline icon-tabler-brand-git"
  205. >
  206. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  207. <path d="M16 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
  208. <path d="M12 8m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
  209. <path d="M12 16m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
  210. <path d="M12 15v-6" />
  211. <path d="M15 11l-2 -2" />
  212. <path d="M11 7l-1.9 -1.9" />
  213. <path
  214. d="M13.446 2.6l7.955 7.954a2.045 2.045 0 0 1 0 2.892l-7.955 7.955a2.045 2.045 0 0 1 -2.892 0l-7.955 -7.955a2.045 2.045 0 0 1 0 -2.892l7.955 -7.955a2.045 2.045 0 0 1 2.892 0z"
  215. /></svg
  216. ></a>
  217. </div>
  218. <div class="container">
  219. <div class="apps-grid" id="appsGrid">
  220. <div class="loading">加载中……</div>
  221. </div>
  222. </div>
  223. <script src="lib/pinyinjs/pinyin_dict_withtone.js"></script>
  224. <script src="lib/pinyinjs/pinyinUtil.js"></script>
  225. <script>
  226. document.addEventListener("DOMContentLoaded", async () => {
  227. const appsGrid = document.getElementById("appsGrid");
  228. const searchInput = document.getElementById("searchInput");
  229. let packages = [];
  230. // 加载应用数据
  231. async function loadPackages() {
  232. try {
  233. const response = await fetch("index.json");
  234. const data = await response.json();
  235. packages = (data.packages || []).map(pkg => ({
  236. ...pkg,
  237. pinyin: pinyinUtil.getPinyin(pkg.name, "", false) // 添加拼音字段
  238. }));
  239. renderApps(packages);
  240. } catch (error) {
  241. appsGrid.innerHTML = `<div class="loading">加载失败: ${error.message}</div>`;
  242. }
  243. }
  244. // 渲染应用列表
  245. function renderApps(appList) {
  246. if (appList.length === 0) {
  247. appsGrid.innerHTML = '<div class="loading">未找到匹配的应用</div>';
  248. translate.execute([appsGrid]);
  249. return;
  250. }
  251. appsGrid.innerHTML = appList
  252. .map((pkg) => {
  253. // 处理图标显示
  254. let iconContent = "";
  255. if (pkg.icon) {
  256. // 如果有图标 URL,使用 img 标签
  257. iconContent = `<img src="${pkg.location}/${pkg.icon}" alt="${pkg.name}" style="width:100%;height:100%;object-fit:contain;">`;
  258. } else {
  259. // 如果没有图标,显示名称首字符
  260. iconContent = pkg.name.charAt(0).toUpperCase();
  261. }
  262. return `
  263. <a href="${pkg.location}/metadata.json" class="app-card" title="${
  264. pkg.description || ""
  265. }" target="_blank" data-menu-options='${JSON.stringify([
  266. { label: "启动应用程序", action: "execute" }, // 新标签页打开 href 指向的 metadata.json 中的 entry 指向的文件
  267. { label: "查看元信息 ", action: "metadata" }, // 新标签页打开 href 指向的 metadata.json
  268. { label: "复制启动地址", action: "cpexec" }, // 复制 href 指向的 metadata.json 中的 entry 指向的文件地址
  269. { label: "复制元文件地址", action: "cpmeta" }, // 复制 href 指向的 metadata.json 的地址
  270. ])}'>
  271. <div class="app-icon">${iconContent}</div>
  272. <div class="app-name">${pkg.name}</div>
  273. <div class="app-author">作者: ${pkg.author}</div>
  274. </a>`;
  275. })
  276. .join("");
  277. translate.execute([appsGrid]);
  278. }
  279. // 搜索功能
  280. searchInput.addEventListener("input", () => {
  281. const query = searchInput.value.toLowerCase().trim();
  282. if (!query) {
  283. renderApps(packages);
  284. return;
  285. }
  286. const filtered = packages.filter(
  287. (pkg) =>
  288. pkg.name.toLowerCase().includes(query) ||
  289. (pkg.pinyin && pkg.pinyin.includes(query)) || // 支持拼音搜索
  290. pkg.author.toLowerCase().includes(query) ||
  291. (pkg.description &&
  292. pkg.description.toLowerCase().includes(query)) ||
  293. pkg.id.toLowerCase().includes(query)
  294. );
  295. renderApps(filtered);
  296. });
  297. // 初始化
  298. await loadPackages();
  299. });
  300. // 自定义右键菜单功能
  301. function initOptionMenu(doc) {
  302. // 初始化样式
  303. var style = doc.createElement("style");
  304. style.type = "text/css";
  305. style.innerHTML = `
  306. #custom-context-menu {
  307. transition: all 0.2s ease;
  308. --accent-color: #64ffda; /* 强调色:边框 */
  309. --secondary-color: #00695c; /* 次要色:未激活边框 */
  310. --danger-color: #ff6d00; /* 着重色:边框 */
  311. --accent-bg-color: #009688;
  312. --secondary-bg-color: #616161;
  313. --content-bg-color: #424242;
  314. --accent-font-color: #f5f5f5;
  315. --secondary-font-color: #eeeeee;
  316. --margin-padding: 0.5rem;
  317. --border-thickness: 0.2rem;
  318. --border-radius: 0.5rem;
  319. --title-bar-height: 2rem;
  320. --title-bar-justify-content: left;
  321. --task-bar-height: 3rem;
  322. --shadow: 0.6rem 0.6rem 0.1rem 0.1rem rgba(0, 0, 0, 0.2);
  323. --focused-bg-color: rgba(255, 255, 255, 0.1);
  324. font-size: small;
  325. user-select: none;
  326. position: absolute;
  327. background-color: var(--content-bg-color);
  328. border: var(--border-thickness) solid var(--secondary-color);
  329. border-radius: var(--border-radius);
  330. padding: 0;
  331. opacity: 0;
  332. transform: scale(0.8);
  333. pointer-events: none;
  334. z-index: 4000; /* 确保在顶层 */
  335. min-width: 150px;
  336. &.show {
  337. display: block;
  338. opacity: 1;
  339. transform: scale(1);
  340. pointer-events: auto;
  341. }
  342. &:hover {
  343. box-shadow: var(--shadow);
  344. --secondary-color: var(--accent-color);
  345. }
  346. }
  347. #custom-context-menu ul {
  348. list-style: none;
  349. margin: 0;
  350. padding: 0;
  351. }
  352. #custom-context-menu li {
  353. padding: var(--margin-padding);
  354. cursor: pointer;
  355. list-style-type: none; /* 去除列表项标记 */
  356. }
  357. #custom-context-menu li:hover {
  358. background-color: var(--focused-bg-color);
  359. }`;
  360. style.id = "addStyle";
  361. doc.getElementsByTagName("HEAD").item(0).appendChild(style);
  362. // 初始化元素
  363. const contextMenu = doc.createElement("ul");
  364. contextMenu.id = "custom-context-menu";
  365. doc.body.appendChild(contextMenu);
  366. // 监听全局右键点击事件
  367. doc.addEventListener("contextmenu", function (e) {
  368. // 阻止默认右键菜单
  369. e.preventDefault();
  370. // 获取被点击的元素
  371. const target = e.target;
  372. const selection = window.getSelection();
  373. const hasSelection =
  374. selection && selection.toString().trim().length > 0;
  375. // 检查事件目标是否在选区内
  376. let inSelection = false;
  377. if (hasSelection && selection.rangeCount > 0) {
  378. const range = selection.getRangeAt(0);
  379. inSelection = range.intersectsNode(e.target);
  380. }
  381. // 如果有文本被选中且右键点击在选区内,显示默认文本操作菜单
  382. if (hasSelection && inSelection) {
  383. const defaultTextOptions = [
  384. { label: "复制", action: "copy" },
  385. { label: "剪切", action: "cut" },
  386. { label: "粘贴", action: "paste" },
  387. { label: "全选", action: "selectAll" },
  388. ];
  389. // 清空菜单
  390. contextMenu.innerHTML = "";
  391. // 生成菜单项
  392. defaultTextOptions.forEach((option) => {
  393. const li = doc.createElement("li");
  394. li.textContent = option.label;
  395. li.onclick = function () {
  396. if (option.action === "copy") {
  397. doc.execCommand("copy");
  398. } else if (option.action === "cut") {
  399. doc.execCommand("cut");
  400. } else if (option.action === "paste") {
  401. doc.execCommand("paste");
  402. } else if (option.action === "selectAll") {
  403. doc.execCommand("selectAll");
  404. }
  405. contextMenu.classList.remove("show");
  406. };
  407. contextMenu.appendChild(li);
  408. });
  409. // 显示菜单(确保在屏幕内)
  410. translate.execute([contextMenu]);
  411. contextMenu.classList.add("show");
  412. // 获取菜单尺寸
  413. const menuWidth = contextMenu.offsetWidth;
  414. const menuHeight = contextMenu.offsetHeight;
  415. // 计算调整后的位置
  416. let adjustedLeft = e.pageX;
  417. let adjustedTop = e.pageY;
  418. // 如果靠近右边缘,向左偏移
  419. if (window.innerWidth - e.pageX < menuWidth) {
  420. adjustedLeft = e.pageX - menuWidth;
  421. }
  422. // 如果靠近下边缘,向上偏移
  423. if (window.innerHeight - e.pageY < menuHeight) {
  424. adjustedTop = e.pageY - menuHeight;
  425. }
  426. contextMenu.style.left = adjustedLeft + "px";
  427. contextMenu.style.top = adjustedTop + "px";
  428. }
  429. // 否则检查元素的 data-menu-options 属性
  430. else if (target.dataset.menuOptions) {
  431. try {
  432. // 解析JSON字符串
  433. const menuOptions = JSON.parse(target.dataset.menuOptions);
  434. // 清空菜单
  435. contextMenu.innerHTML = "";
  436. // 动态生成菜单项
  437. menuOptions.forEach((option) => {
  438. const li = doc.createElement("li");
  439. li.textContent = option.label;
  440. li.onclick = function () {
  441. // 执行action
  442. if (option.action) {
  443. // 触发自定义事件
  444. const event = new CustomEvent("custom-contextmenu-action", {
  445. detail: {
  446. action: option.action,
  447. target: target,
  448. },
  449. });
  450. doc.dispatchEvent(event);
  451. }
  452. // 隐藏菜单
  453. contextMenu.classList.remove("show");
  454. };
  455. contextMenu.appendChild(li);
  456. });
  457. // 显示菜单(确保在屏幕内)
  458. translate.execute([contextMenu]);
  459. contextMenu.classList.add("show");
  460. // 获取菜单尺寸
  461. const menuWidth = contextMenu.offsetWidth;
  462. const menuHeight = contextMenu.offsetHeight;
  463. // 计算调整后的位置
  464. let adjustedLeft = e.pageX;
  465. let adjustedTop = e.pageY;
  466. // 如果靠近右边缘,向左偏移
  467. if (window.innerWidth - e.pageX < menuWidth) {
  468. adjustedLeft = e.pageX - menuWidth;
  469. }
  470. // 如果靠近下边缘,向上偏移
  471. if (window.innerHeight - e.pageY < menuHeight) {
  472. adjustedTop = e.pageY - menuHeight;
  473. }
  474. contextMenu.style.left = adjustedLeft + "px";
  475. contextMenu.style.top = adjustedTop + "px";
  476. } catch (error) {
  477. console.error("解析菜单选项失败", error);
  478. }
  479. } else {
  480. // 如果没有定义菜单选项,则隐藏菜单
  481. contextMenu.classList.remove("show");
  482. }
  483. });
  484. // 点击其他地方隐藏菜单
  485. doc.addEventListener("click", function () {
  486. contextMenu.classList.remove("show");
  487. });
  488. // 阻止菜单内部的点击事件冒泡
  489. contextMenu.addEventListener("click", function (e) {
  490. e.stopPropagation();
  491. });
  492. }
  493. // 处理右键菜单动作
  494. document.addEventListener("custom-contextmenu-action", function (e) {
  495. const { action, target } = e.detail;
  496. const metadataUrl = target.href;
  497. // 获取 metadata.json 内容
  498. async function getMetadata() {
  499. try {
  500. const response = await fetch(metadataUrl);
  501. return await response.json();
  502. } catch (error) {
  503. console.error("获取 metadata.json 失败:", error);
  504. return null;
  505. }
  506. }
  507. if (action === "execute") {
  508. // 启动应用程序:新标签页打开 metadata.json 中的 entry 指向的文件
  509. getMetadata().then((metadata) => {
  510. if (metadata && metadata.entry) {
  511. const entryUrl = new URL(metadata.entry, metadataUrl).href;
  512. window.open(entryUrl, "_blank");
  513. }
  514. });
  515. } else if (action === "metadata") {
  516. // 查看元信息:新标签页打开 metadata.json
  517. window.open(metadataUrl, "_blank");
  518. } else if (action === "cpexec") {
  519. // 复制启动地址:复制 metadata.json 中的 entry 指向的文件地址
  520. getMetadata().then((metadata) => {
  521. if (metadata && metadata.entry) {
  522. const entryUrl = new URL(metadata.entry, metadataUrl).href;
  523. navigator.clipboard.writeText(entryUrl).catch((err) => {
  524. console.error("复制失败:", err);
  525. });
  526. }
  527. });
  528. } else if (action === "cpmeta") {
  529. // 复制元文件地址:复制 metadata.json 的地址
  530. navigator.clipboard.writeText(metadataUrl).catch((err) => {
  531. console.error("复制失败:", err);
  532. });
  533. }
  534. });
  535. initOptionMenu(document);
  536. // 加载 CSS
  537. function loadCSS(url) {
  538. return new Promise((resolve, reject) => {
  539. //// 检查是否已加载
  540. const existingLinks = document.querySelectorAll(
  541. `link[href="${url}"]`
  542. );
  543. if (existingLinks.length > 0) {
  544. return resolve(url);
  545. }
  546. //// 创建新的 link 元素
  547. const link = document.createElement("link");
  548. link.rel = "stylesheet";
  549. link.type = "text/css";
  550. link.href = url;
  551. //// 成功加载处理
  552. link.onload = () => {
  553. link.onload = null;
  554. link.onerror = null;
  555. resolve(url);
  556. };
  557. //// 加载失败处理
  558. link.onerror = () => {
  559. link.onerror = null;
  560. link.onload = null;
  561. document.head.removeChild(link);
  562. reject(new Error(`无法加载 CSS 文件: ${url}`));
  563. };
  564. //// 添加到文档头部
  565. document.head.appendChild(link);
  566. });
  567. }
  568. // translate-js 翻译系统
  569. //// 初始化翻译系统
  570. function initTranslate() {
  571. try {
  572. translate.service.use("client.edge");
  573. translate.request.listener.start();
  574. translate.setAutoDiscriminateLocalLanguage();
  575. translate.language.setUrlParamControl();
  576. translate.ignore.class.push("notTranslate");
  577. translate.execute();
  578. } catch (e) {
  579. console.error("翻译系统出错:" + e);
  580. }
  581. }
  582. //// 刷新翻译
  583. function refreshTranslate() {
  584. try {
  585. translate.selectLanguageTag.refreshRender();
  586. } catch (e) {
  587. console.error("刷新翻译出错:" + e);
  588. }
  589. }
  590. // 初始化
  591. function initialize() {
  592. initTranslate(); //// 初始化页面翻译
  593. loadCSS(
  594. "https://chinese-fonts-cdn.deno.dev/packages/maple-mono-cn/dist/MapleMono-CN-Regular/result.css"
  595. ); //// 加载字体 CSS
  596. }
  597. // 触发器
  598. //// 网页加载完毕后触发初始化
  599. window.addEventListener("DOMContentLoaded", () => initialize());
  600. </script>
  601. </body>
  602. </html>