index.html 22 KB

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