index.html 23 KB

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