index.html 24 KB

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