index.html 26 KB

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