index.html 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  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 id="translate" class="top-buttons language-selector" title="语言">
  246. <svg
  247. xmlns="http://www.w3.org/2000/svg"
  248. width="24"
  249. height="24"
  250. viewBox="0 0 24 24"
  251. fill="none"
  252. stroke="currentColor"
  253. stroke-width="2"
  254. stroke-linecap="round"
  255. stroke-linejoin="round"
  256. class="icon icon-tabler icons-tabler-outline icon-tabler-world"
  257. >
  258. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  259. <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
  260. <path d="M3.6 9h16.8" />
  261. <path d="M3.6 15h16.8" />
  262. <path d="M11.5 3a17 17 0 0 0 0 18" />
  263. <path d="M12.5 3a17 17 0 0 1 0 18" /></svg
  264. ></a>
  265. <a
  266. href="https://github.com/swaybien/pageos-apps"
  267. target="_blank"
  268. class="top-buttons"
  269. title="仓库"
  270. >
  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-brand-git"
  282. >
  283. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  284. <path d="M16 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
  285. <path d="M12 8m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
  286. <path d="M12 16m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
  287. <path d="M12 15v-6" />
  288. <path d="M15 11l-2 -2" />
  289. <path d="M11 7l-1.9 -1.9" />
  290. <path
  291. 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"
  292. /></svg
  293. ></a>
  294. </div>
  295. <div class="container">
  296. <div class="apps-grid" id="appsGrid">
  297. <div class="loading">加载中……</div>
  298. </div>
  299. </div>
  300. <script src="lib/pinyinjs/pinyin_dict_withtone.js"></script>
  301. <script src="lib/pinyinjs/pinyinUtil.js"></script>
  302. <script>
  303. document.addEventListener("DOMContentLoaded", async () => {
  304. const appsGrid = document.getElementById("appsGrid");
  305. const searchInput = document.getElementById("searchInput");
  306. let packages = [];
  307. // 加载应用程序数据
  308. async function loadPackages() {
  309. try {
  310. const response = await fetch("index.json");
  311. const data = await response.json();
  312. packages = (data.packages || []).map((pkg) => ({
  313. ...pkg,
  314. pinyin: pinyinUtil.getPinyin(pkg.name, "", false), // 添加拼音字段
  315. }));
  316. renderApps(packages);
  317. } catch (error) {
  318. appsGrid.innerHTML = `<div class="loading">加载失败: ${error.message}</div>`;
  319. }
  320. }
  321. // 渲染应用程序列表
  322. function renderApps(appList) {
  323. if (appList.length === 0) {
  324. appsGrid.innerHTML =
  325. '<div class="loading">未找到匹配的应用程序</div>';
  326. translate.execute([appsGrid]);
  327. return;
  328. }
  329. appsGrid.innerHTML = appList
  330. .map((pkg) => {
  331. // 处理图标显示
  332. let iconContent = "";
  333. if (pkg.icon) {
  334. // 如果有图标 URL,使用 img 标签
  335. iconContent = `<img src="${pkg.location}/${pkg.icon}" alt="${
  336. pkg.name || pkg.id
  337. }" style="width:100%;height:100%;object-fit:contain;">`;
  338. } else {
  339. // 如果没有图标,显示名称首字符
  340. iconContent = pkg.name.charAt(0).toUpperCase();
  341. }
  342. return `
  343. <button data-href="${
  344. pkg.location
  345. }/metadata.json" class="app-card" title="${
  346. pkg.description || pkg.name || pkg.id
  347. }" target="_blank" data-menu-options='${JSON.stringify([
  348. { label: "启动应用程序", action: "execute" }, // 新标签页打开 href 指向的 metadata.json 中的 entry 指向的文件
  349. { label: "查看元信息 ", action: "metadata" }, // 新标签页打开 href 指向的 metadata.json
  350. { label: "复制启动地址", action: "cpexec" }, // 复制 href 指向的 metadata.json 中的 entry 指向的文件地址
  351. { label: "复制元文件地址", action: "cpmeta" }, // 复制 href 指向的 metadata.json 的地址
  352. ])}'>
  353. <div class="app-icon">${iconContent}</div>
  354. <div class="app-name">${pkg.name || pkg.id}</div>
  355. <div class="app-author">作者: ${pkg.author}</div>
  356. </button>`;
  357. })
  358. .join("");
  359. translate.execute([appsGrid]);
  360. }
  361. // 搜索功能 - 已添加防抖
  362. let searchTimeout = null;
  363. searchInput.addEventListener("input", () => {
  364. // 清除之前的定时器
  365. if (searchTimeout) {
  366. clearTimeout(searchTimeout);
  367. }
  368. const query = searchInput.value.toLowerCase().trim();
  369. if (!query) {
  370. renderApps(packages);
  371. return;
  372. }
  373. // 设置新的定时器,延迟执行搜索
  374. searchTimeout = setTimeout(() => {
  375. const filtered = packages.filter(
  376. (pkg) =>
  377. pkg.name.toLowerCase().includes(query) ||
  378. (pkg.pinyin && pkg.pinyin.includes(query)) || // 支持拼音搜索
  379. pkg.author.toLowerCase().includes(query) ||
  380. (pkg.description &&
  381. pkg.description.toLowerCase().includes(query)) ||
  382. pkg.id.toLowerCase().includes(query)
  383. );
  384. renderApps(filtered);
  385. }, 300); // 300ms 防抖延迟
  386. });
  387. // 初始化
  388. await loadPackages();
  389. });
  390. // 自定义右键菜单功能
  391. function initOptionMenu(doc) {
  392. // 隐藏菜单后,将菜单移动到屏幕内
  393. function inScreen(contextMenu) {
  394. contextMenu.style.left = "2px";
  395. contextMenu.style.top = "2px";
  396. }
  397. // 初始化样式
  398. var style = doc.createElement("style");
  399. style.type = "text/css";
  400. style.innerHTML = `
  401. #custom-context-menu {
  402. transition: all 0.2s ease;
  403. --accent-color: #64ffda; /* 强调色:边框 */
  404. --secondary-color: #00695c; /* 次要色:未激活边框 */
  405. --danger-color: #ff6d00; /* 着重色:边框 */
  406. --accent-bg-color: #009688;
  407. --secondary-bg-color: #616161;
  408. --content-bg-color: #424242;
  409. --accent-font-color: #f5f5f5;
  410. --secondary-font-color: #eeeeee;
  411. --margin-padding: 0.5rem;
  412. --border-thickness: 0.2rem;
  413. --border-radius: 0.5rem;
  414. --title-bar-height: 2rem;
  415. --title-bar-justify-content: left;
  416. --task-bar-height: 3rem;
  417. --shadow: 0.6rem 0.6rem 0.1rem 0.1rem rgba(0, 0, 0, 0.2);
  418. --focused-bg-color: rgba(255, 255, 255, 0.1);
  419. font-size: small;
  420. user-select: none;
  421. position: absolute;
  422. background-color: var(--content-bg-color);
  423. border: var(--border-thickness) solid var(--secondary-color);
  424. border-radius: var(--border-radius);
  425. padding: 0;
  426. opacity: 0;
  427. transform: scale(0.8);
  428. pointer-events: none;
  429. z-index: 4000; /* 确保在顶层 */
  430. min-width: 150px;
  431. &.show {
  432. display: block;
  433. opacity: 1;
  434. transform: scale(1);
  435. pointer-events: auto;
  436. }
  437. &:hover {
  438. box-shadow: var(--shadow);
  439. --secondary-color: var(--accent-color);
  440. }
  441. }
  442. #custom-context-menu ul {
  443. list-style: none;
  444. margin: 0;
  445. padding: 0;
  446. }
  447. #custom-context-menu li {
  448. padding: var(--margin-padding);
  449. cursor: pointer;
  450. list-style-type: none; /* 去除列表项标记 */
  451. }
  452. #custom-context-menu li:hover {
  453. background-color: var(--focused-bg-color);
  454. }`;
  455. style.id = "addStyle";
  456. doc.getElementsByTagName("HEAD").item(0).appendChild(style);
  457. // 初始化元素
  458. const contextMenu = doc.createElement("ul");
  459. contextMenu.id = "custom-context-menu";
  460. doc.body.appendChild(contextMenu);
  461. function f(e) {
  462. // 阻止默认右键菜单
  463. e.preventDefault();
  464. // 获取被点击的元素
  465. const target = e.target;
  466. const selection = window.getSelection();
  467. const hasSelection =
  468. selection && selection.toString().trim().length > 0;
  469. // 检查事件目标是否在选区内
  470. let inSelection = false;
  471. if (hasSelection && selection.rangeCount > 0) {
  472. const range = selection.getRangeAt(0);
  473. inSelection = range.intersectsNode(e.target);
  474. }
  475. // 如果有文本被选中且右键点击在选区内,显示默认文本操作菜单
  476. if (hasSelection && inSelection) {
  477. const defaultTextOptions = [
  478. { label: "复制", action: "copy" },
  479. { label: "剪切", action: "cut" },
  480. { label: "粘贴", action: "paste" },
  481. { label: "全选", action: "selectAll" },
  482. ];
  483. // 清空菜单
  484. contextMenu.innerHTML = "";
  485. // 生成菜单项
  486. defaultTextOptions.forEach((option) => {
  487. const li = doc.createElement("li");
  488. li.textContent = option.label;
  489. li.onclick = function () {
  490. if (option.action === "copy") {
  491. doc.execCommand("copy");
  492. } else if (option.action === "cut") {
  493. doc.execCommand("cut");
  494. } else if (option.action === "paste") {
  495. doc.execCommand("paste");
  496. } else if (option.action === "selectAll") {
  497. doc.execCommand("selectAll");
  498. }
  499. contextMenu.classList.remove("show");
  500. inScreen(contextMenu);
  501. };
  502. contextMenu.appendChild(li);
  503. });
  504. // 显示菜单(确保在屏幕内)
  505. translate.execute([contextMenu]);
  506. contextMenu.classList.add("show");
  507. // 获取菜单尺寸
  508. const menuWidth = contextMenu.offsetWidth;
  509. const menuHeight = contextMenu.offsetHeight;
  510. // 计算调整后的位置
  511. let adjustedLeft = e.pageX;
  512. let adjustedTop = e.pageY;
  513. // 如果靠近右边缘,向左偏移
  514. if (window.innerWidth - e.pageX < menuWidth) {
  515. adjustedLeft = e.pageX - menuWidth;
  516. }
  517. // 如果靠近下边缘,向上偏移
  518. if (window.innerHeight - e.pageY < menuHeight) {
  519. adjustedTop = e.pageY - menuHeight;
  520. }
  521. contextMenu.style.left = adjustedLeft + "px";
  522. contextMenu.style.top = adjustedTop + "px";
  523. }
  524. // 否则检查元素的 data-menu-options 属性
  525. else if (target.dataset.menuOptions) {
  526. try {
  527. // 解析JSON字符串
  528. const menuOptions = JSON.parse(target.dataset.menuOptions);
  529. // 清空菜单
  530. contextMenu.innerHTML = "";
  531. // 动态生成菜单项
  532. menuOptions.forEach((option) => {
  533. const li = doc.createElement("li");
  534. li.textContent = option.label;
  535. li.onclick = function () {
  536. // 执行action
  537. if (option.action) {
  538. // 触发自定义事件
  539. const event = new CustomEvent("custom-contextmenu-action", {
  540. detail: {
  541. action: option.action,
  542. target: target,
  543. },
  544. });
  545. doc.dispatchEvent(event);
  546. }
  547. // 隐藏菜单
  548. contextMenu.classList.remove("show");
  549. inScreen(contextMenu);
  550. };
  551. contextMenu.appendChild(li);
  552. });
  553. // 显示菜单(确保在屏幕内)
  554. translate.execute([contextMenu]);
  555. contextMenu.classList.add("show");
  556. // 获取菜单尺寸
  557. const menuWidth = contextMenu.offsetWidth;
  558. const menuHeight = contextMenu.offsetHeight;
  559. // 计算调整后的位置
  560. let adjustedLeft = e.pageX;
  561. let adjustedTop = e.pageY;
  562. // 如果靠近右边缘,向左偏移
  563. if (window.innerWidth - e.pageX < menuWidth) {
  564. adjustedLeft = e.pageX - menuWidth;
  565. }
  566. // 如果靠近下边缘,向上偏移
  567. if (window.innerHeight - e.pageY < menuHeight) {
  568. adjustedTop = e.pageY - menuHeight;
  569. }
  570. contextMenu.style.left = adjustedLeft + "px";
  571. contextMenu.style.top = adjustedTop + "px";
  572. } catch (error) {
  573. console.error("解析菜单选项失败", error);
  574. }
  575. } else {
  576. // 如果没有定义菜单选项,则隐藏菜单
  577. contextMenu.classList.remove("show");
  578. inScreen(contextMenu);
  579. }
  580. }
  581. // 监听全局右键点击事件
  582. doc.addEventListener("contextmenu", function (e) {
  583. f(e);
  584. });
  585. // 监听全局左键点击事件,点击其他地方隐藏菜单
  586. doc.addEventListener("click", function (e) {
  587. if (e.target.closest("button.app-card")) {
  588. f(e);
  589. } else {
  590. contextMenu.classList.remove("show");
  591. inScreen(contextMenu);
  592. }
  593. });
  594. // 阻止菜单内部的点击事件冒泡
  595. contextMenu.addEventListener("click", function (e) {
  596. e.stopPropagation();
  597. });
  598. }
  599. // 处理右键菜单动作
  600. document.addEventListener("custom-contextmenu-action", function (e) {
  601. const { action, target } = e.detail;
  602. const metadataUrl = target.dataset.href;
  603. // 获取 metadata.json 内容
  604. async function getMetadata() {
  605. try {
  606. const response = await fetch(metadataUrl);
  607. return await response.json();
  608. } catch (error) {
  609. console.error("获取 metadata.json 失败:", error);
  610. return null;
  611. }
  612. }
  613. if (action === "execute") {
  614. // 启动应用程序:新标签页打开 metadata.json 中的 entry 指向的文件
  615. getMetadata().then((metadata) => {
  616. if (metadata && metadata.entry) {
  617. const entryUrl = new URL(
  618. metadata.entry,
  619. new URL(metadataUrl, window.location.href).href
  620. ).href;
  621. window.open(entryUrl, "_blank");
  622. }
  623. });
  624. } else if (action === "metadata") {
  625. // 查看元信息:新标签页打开 metadata.json
  626. window.open(metadataUrl, "_blank");
  627. } else if (action === "cpexec") {
  628. // 复制启动地址:复制 metadata.json 中的 entry 指向的文件地址
  629. getMetadata().then((metadata) => {
  630. if (metadata && metadata.entry) {
  631. const entryUrl = new URL(
  632. metadata.entry,
  633. new URL(metadataUrl, window.location.href).href
  634. ).href;
  635. navigator.clipboard.writeText(entryUrl).catch((err) => {
  636. console.error("复制失败:", err);
  637. });
  638. }
  639. });
  640. } else if (action === "cpmeta") {
  641. // 复制元文件地址:复制 metadata.json 的地址
  642. navigator.clipboard.writeText(metadataUrl).catch((err) => {
  643. console.error("复制失败:", err);
  644. });
  645. }
  646. });
  647. initOptionMenu(document);
  648. // 加载 CSS
  649. function loadCSS(url) {
  650. return new Promise((resolve, reject) => {
  651. //// 检查是否已加载
  652. const existingLinks = document.querySelectorAll(
  653. `link[href="${url}"]`
  654. );
  655. if (existingLinks.length > 0) {
  656. return resolve(url);
  657. }
  658. //// 创建新的 link 元素
  659. const link = document.createElement("link");
  660. link.rel = "stylesheet";
  661. link.type = "text/css";
  662. link.href = url;
  663. //// 成功加载处理
  664. link.onload = () => {
  665. link.onload = null;
  666. link.onerror = null;
  667. resolve(url);
  668. };
  669. //// 加载失败处理
  670. link.onerror = () => {
  671. link.onerror = null;
  672. link.onload = null;
  673. document.head.removeChild(link);
  674. reject(new Error(`无法加载 CSS 文件: ${url}`));
  675. };
  676. //// 添加到文档头部
  677. document.head.appendChild(link);
  678. });
  679. }
  680. // translate-js 翻译系统
  681. //// 初始化翻译系统
  682. function initTranslate() {
  683. try {
  684. translate.service.use("client.edge");
  685. translate.request.listener.start();
  686. translate.setAutoDiscriminateLocalLanguage();
  687. translate.language.setUrlParamControl();
  688. translate.ignore.class.push("notTranslate");
  689. translate.execute();
  690. } catch (e) {
  691. console.error("翻译系统出错:" + e);
  692. }
  693. }
  694. //// 刷新翻译
  695. function refreshTranslate() {
  696. try {
  697. translate.selectLanguageTag.refreshRender();
  698. } catch (e) {
  699. console.error("刷新翻译出错:" + e);
  700. }
  701. }
  702. // 初始化
  703. function initialize() {
  704. initTranslate(); //// 初始化页面翻译
  705. loadCSS(
  706. "https://chinese-fonts-cdn.deno.dev/packages/maple-mono-cn/dist/MapleMono-CN-Regular/result.css"
  707. ); //// 加载字体 CSS
  708. }
  709. // 触发器
  710. //// 网页加载完毕后触发初始化
  711. window.addEventListener("DOMContentLoaded", () => initialize());
  712. </script>
  713. </body>
  714. </html>