index.html 29 KB

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