2
0

index.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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>
  224. document.addEventListener("DOMContentLoaded", async () => {
  225. const appsGrid = document.getElementById("appsGrid");
  226. const searchInput = document.getElementById("searchInput");
  227. let packages = [];
  228. // 加载应用数据
  229. async function loadPackages() {
  230. try {
  231. const response = await fetch("index.json");
  232. const data = await response.json();
  233. packages = data.packages || [];
  234. renderApps(packages);
  235. } catch (error) {
  236. appsGrid.innerHTML = `<div class="loading">加载失败: ${error.message}</div>`;
  237. }
  238. }
  239. // 渲染应用列表
  240. function renderApps(appList) {
  241. if (appList.length === 0) {
  242. appsGrid.innerHTML = '<div class="loading">未找到匹配的应用</div>';
  243. translate.execute([appsGrid]);
  244. return;
  245. }
  246. appsGrid.innerHTML = appList
  247. .map((pkg) => {
  248. // 处理图标显示
  249. let iconContent = "";
  250. if (pkg.icon) {
  251. // 如果有图标 URL,使用 img 标签
  252. iconContent = `<img src="${pkg.location}/${pkg.icon}" alt="${pkg.name}" style="width:100%;height:100%;object-fit:contain;">`;
  253. } else {
  254. // 如果没有图标,显示名称首字符
  255. iconContent = pkg.name.charAt(0).toUpperCase();
  256. }
  257. return `
  258. <a href="${pkg.location}/metadata.json" class="app-card" title="${
  259. pkg.description || ""
  260. }" target="_blank" data-menu-options='${JSON.stringify([
  261. { label: "启动应用程序", action: "execute" }, // 新标签页打开 href 指向的 metadata.json 中的 entry 指向的文件
  262. { label: "查看元信息 ", action: "metadata" }, // 新标签页打开 href 指向的 metadata.json
  263. { label: "复制启动地址", action: "cpexec" }, // 复制 href 指向的 metadata.json 中的 entry 指向的文件地址
  264. { label: "复制元文件地址", action: "cpmeta" }, // 复制 href 指向的 metadata.json 的地址
  265. ])}'>
  266. <div class="app-icon">${iconContent}</div>
  267. <div class="app-name">${pkg.name}</div>
  268. <div class="app-author">作者: ${pkg.author}</div>
  269. </a>`;
  270. })
  271. .join("");
  272. translate.execute([appsGrid]);
  273. }
  274. // 搜索功能
  275. searchInput.addEventListener("input", () => {
  276. const query = searchInput.value.toLowerCase().trim();
  277. if (!query) {
  278. renderApps(packages);
  279. return;
  280. }
  281. const filtered = packages.filter(
  282. (pkg) =>
  283. pkg.name.toLowerCase().includes(query) ||
  284. pkg.author.toLowerCase().includes(query) ||
  285. (pkg.description &&
  286. pkg.description.toLowerCase().includes(query)) ||
  287. pkg.id.toLowerCase().includes(query)
  288. );
  289. renderApps(filtered);
  290. });
  291. // 初始化
  292. await loadPackages();
  293. });
  294. // 自定义右键菜单功能
  295. function initOptionMenu(doc) {
  296. // 初始化样式
  297. var style = doc.createElement("style");
  298. style.type = "text/css";
  299. style.innerHTML = `
  300. #custom-context-menu {
  301. transition: all 0.2s ease;
  302. --accent-color: #64ffda; /* 强调色:边框 */
  303. --secondary-color: #00695c; /* 次要色:未激活边框 */
  304. --danger-color: #ff6d00; /* 着重色:边框 */
  305. --accent-bg-color: #009688;
  306. --secondary-bg-color: #616161;
  307. --content-bg-color: #424242;
  308. --accent-font-color: #f5f5f5;
  309. --secondary-font-color: #eeeeee;
  310. --margin-padding: 0.5rem;
  311. --border-thickness: 0.2rem;
  312. --border-radius: 0.5rem;
  313. --title-bar-height: 2rem;
  314. --title-bar-justify-content: left;
  315. --task-bar-height: 3rem;
  316. --shadow: 0.6rem 0.6rem 0.1rem 0.1rem rgba(0, 0, 0, 0.2);
  317. --focused-bg-color: rgba(255, 255, 255, 0.1);
  318. font-size: small;
  319. user-select: none;
  320. position: absolute;
  321. background-color: var(--content-bg-color);
  322. border: var(--border-thickness) solid var(--secondary-color);
  323. border-radius: var(--border-radius);
  324. padding: 0;
  325. opacity: 0;
  326. transform: scale(0.8);
  327. pointer-events: none;
  328. z-index: 4000; /* 确保在顶层 */
  329. min-width: 150px;
  330. &.show {
  331. display: block;
  332. opacity: 1;
  333. transform: scale(1);
  334. pointer-events: auto;
  335. }
  336. &:hover {
  337. box-shadow: var(--shadow);
  338. --secondary-color: var(--accent-color);
  339. }
  340. }
  341. #custom-context-menu ul {
  342. list-style: none;
  343. margin: 0;
  344. padding: 0;
  345. }
  346. #custom-context-menu li {
  347. padding: var(--margin-padding);
  348. cursor: pointer;
  349. list-style-type: none; /* 去除列表项标记 */
  350. }
  351. #custom-context-menu li:hover {
  352. background-color: var(--focused-bg-color);
  353. }`;
  354. style.id = "addStyle";
  355. doc.getElementsByTagName("HEAD").item(0).appendChild(style);
  356. // 初始化元素
  357. const contextMenu = doc.createElement("ul");
  358. contextMenu.id = "custom-context-menu";
  359. doc.body.appendChild(contextMenu);
  360. // 监听全局右键点击事件
  361. doc.addEventListener("contextmenu", function (e) {
  362. // 阻止默认右键菜单
  363. e.preventDefault();
  364. // 获取被点击的元素
  365. const target = e.target;
  366. const selection = window.getSelection();
  367. const hasSelection =
  368. selection && selection.toString().trim().length > 0;
  369. // 检查事件目标是否在选区内
  370. let inSelection = false;
  371. if (hasSelection && selection.rangeCount > 0) {
  372. const range = selection.getRangeAt(0);
  373. inSelection = range.intersectsNode(e.target);
  374. }
  375. // 如果有文本被选中且右键点击在选区内,显示默认文本操作菜单
  376. if (hasSelection && inSelection) {
  377. const defaultTextOptions = [
  378. { label: "复制", action: "copy" },
  379. { label: "剪切", action: "cut" },
  380. { label: "粘贴", action: "paste" },
  381. { label: "全选", action: "selectAll" },
  382. ];
  383. // 清空菜单
  384. contextMenu.innerHTML = "";
  385. // 生成菜单项
  386. defaultTextOptions.forEach((option) => {
  387. const li = doc.createElement("li");
  388. li.textContent = option.label;
  389. li.onclick = function () {
  390. if (option.action === "copy") {
  391. doc.execCommand("copy");
  392. } else if (option.action === "cut") {
  393. doc.execCommand("cut");
  394. } else if (option.action === "paste") {
  395. doc.execCommand("paste");
  396. } else if (option.action === "selectAll") {
  397. doc.execCommand("selectAll");
  398. }
  399. contextMenu.classList.remove("show");
  400. };
  401. contextMenu.appendChild(li);
  402. });
  403. // 显示菜单(确保在屏幕内)
  404. translate.execute([contextMenu]);
  405. contextMenu.classList.add("show");
  406. // 获取菜单尺寸
  407. const menuWidth = contextMenu.offsetWidth;
  408. const menuHeight = contextMenu.offsetHeight;
  409. // 计算调整后的位置
  410. let adjustedLeft = e.pageX;
  411. let adjustedTop = e.pageY;
  412. // 如果靠近右边缘,向左偏移
  413. if (window.innerWidth - e.pageX < menuWidth) {
  414. adjustedLeft = e.pageX - menuWidth;
  415. }
  416. // 如果靠近下边缘,向上偏移
  417. if (window.innerHeight - e.pageY < menuHeight) {
  418. adjustedTop = e.pageY - menuHeight;
  419. }
  420. contextMenu.style.left = adjustedLeft + "px";
  421. contextMenu.style.top = adjustedTop + "px";
  422. }
  423. // 否则检查元素的 data-menu-options 属性
  424. else if (target.dataset.menuOptions) {
  425. try {
  426. // 解析JSON字符串
  427. const menuOptions = JSON.parse(target.dataset.menuOptions);
  428. // 清空菜单
  429. contextMenu.innerHTML = "";
  430. // 动态生成菜单项
  431. menuOptions.forEach((option) => {
  432. const li = doc.createElement("li");
  433. li.textContent = option.label;
  434. li.onclick = function () {
  435. // 执行action
  436. if (option.action) {
  437. // 触发自定义事件
  438. const event = new CustomEvent("custom-contextmenu-action", {
  439. detail: {
  440. action: option.action,
  441. target: target,
  442. },
  443. });
  444. doc.dispatchEvent(event);
  445. }
  446. // 隐藏菜单
  447. contextMenu.classList.remove("show");
  448. };
  449. contextMenu.appendChild(li);
  450. });
  451. // 显示菜单(确保在屏幕内)
  452. translate.execute([contextMenu]);
  453. contextMenu.classList.add("show");
  454. // 获取菜单尺寸
  455. const menuWidth = contextMenu.offsetWidth;
  456. const menuHeight = contextMenu.offsetHeight;
  457. // 计算调整后的位置
  458. let adjustedLeft = e.pageX;
  459. let adjustedTop = e.pageY;
  460. // 如果靠近右边缘,向左偏移
  461. if (window.innerWidth - e.pageX < menuWidth) {
  462. adjustedLeft = e.pageX - menuWidth;
  463. }
  464. // 如果靠近下边缘,向上偏移
  465. if (window.innerHeight - e.pageY < menuHeight) {
  466. adjustedTop = e.pageY - menuHeight;
  467. }
  468. contextMenu.style.left = adjustedLeft + "px";
  469. contextMenu.style.top = adjustedTop + "px";
  470. } catch (error) {
  471. console.error("解析菜单选项失败", error);
  472. }
  473. } else {
  474. // 如果没有定义菜单选项,则隐藏菜单
  475. contextMenu.classList.remove("show");
  476. }
  477. });
  478. // 点击其他地方隐藏菜单
  479. doc.addEventListener("click", function () {
  480. contextMenu.classList.remove("show");
  481. });
  482. // 阻止菜单内部的点击事件冒泡
  483. contextMenu.addEventListener("click", function (e) {
  484. e.stopPropagation();
  485. });
  486. }
  487. // 处理右键菜单动作
  488. document.addEventListener("custom-contextmenu-action", function (e) {
  489. const { action, target } = e.detail;
  490. const metadataUrl = target.href;
  491. // 获取 metadata.json 内容
  492. async function getMetadata() {
  493. try {
  494. const response = await fetch(metadataUrl);
  495. return await response.json();
  496. } catch (error) {
  497. console.error("获取 metadata.json 失败:", error);
  498. return null;
  499. }
  500. }
  501. if (action === "execute") {
  502. // 启动应用程序:新标签页打开 metadata.json 中的 entry 指向的文件
  503. getMetadata().then((metadata) => {
  504. if (metadata && metadata.entry) {
  505. const entryUrl = new URL(metadata.entry, metadataUrl).href;
  506. window.open(entryUrl, "_blank");
  507. }
  508. });
  509. } else if (action === "metadata") {
  510. // 查看元信息:新标签页打开 metadata.json
  511. window.open(metadataUrl, "_blank");
  512. } else if (action === "cpexec") {
  513. // 复制启动地址:复制 metadata.json 中的 entry 指向的文件地址
  514. getMetadata().then((metadata) => {
  515. if (metadata && metadata.entry) {
  516. const entryUrl = new URL(metadata.entry, metadataUrl).href;
  517. navigator.clipboard.writeText(entryUrl).catch((err) => {
  518. console.error("复制失败:", err);
  519. });
  520. }
  521. });
  522. } else if (action === "cpmeta") {
  523. // 复制元文件地址:复制 metadata.json 的地址
  524. navigator.clipboard.writeText(metadataUrl).catch((err) => {
  525. console.error("复制失败:", err);
  526. });
  527. }
  528. });
  529. initOptionMenu(document);
  530. // 加载 CSS
  531. function loadCSS(url) {
  532. return new Promise((resolve, reject) => {
  533. //// 检查是否已加载
  534. const existingLinks = document.querySelectorAll(
  535. `link[href="${url}"]`
  536. );
  537. if (existingLinks.length > 0) {
  538. return resolve(url);
  539. }
  540. //// 创建新的 link 元素
  541. const link = document.createElement("link");
  542. link.rel = "stylesheet";
  543. link.type = "text/css";
  544. link.href = url;
  545. //// 成功加载处理
  546. link.onload = () => {
  547. link.onload = null;
  548. link.onerror = null;
  549. resolve(url);
  550. };
  551. //// 加载失败处理
  552. link.onerror = () => {
  553. link.onerror = null;
  554. link.onload = null;
  555. document.head.removeChild(link);
  556. reject(new Error(`无法加载 CSS 文件: ${url}`));
  557. };
  558. //// 添加到文档头部
  559. document.head.appendChild(link);
  560. });
  561. }
  562. // translate-js 翻译系统
  563. //// 初始化翻译系统
  564. function initTranslate() {
  565. try {
  566. translate.service.use("client.edge");
  567. translate.request.listener.start();
  568. translate.setAutoDiscriminateLocalLanguage();
  569. translate.language.setUrlParamControl();
  570. translate.ignore.class.push("notTranslate");
  571. translate.execute();
  572. } catch (e) {
  573. console.error("翻译系统出错:" + e);
  574. }
  575. }
  576. //// 刷新翻译
  577. function refreshTranslate() {
  578. try {
  579. translate.selectLanguageTag.refreshRender();
  580. } catch (e) {
  581. console.error("刷新翻译出错:" + e);
  582. }
  583. }
  584. // 初始化
  585. function initialize() {
  586. initTranslate(); //// 初始化页面翻译
  587. loadCSS(
  588. "https://chinese-fonts-cdn.deno.dev/packages/maple-mono-cn/dist/MapleMono-CN-Regular/result.css"
  589. ); //// 加载字体 CSS
  590. }
  591. // 触发器
  592. //// 网页加载完毕后触发初始化
  593. window.addEventListener("DOMContentLoaded", () => initialize());
  594. </script>
  595. </body>
  596. </html>