index.html 28 KB

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