404.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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>404 - 页面未找到</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. justify-content: center;
  33. align-items: center;
  34. --accent-color: #64ffda; /* 强调色:边框 */
  35. --secondary-color: #00695c; /* 次要色:未激活边框 */
  36. --danger-color: #ff6d00; /* 着重色:边框 */
  37. --accent-bg-color: #009688;
  38. --secondary-bg-color: #616161;
  39. --content-bg-color: #424242;
  40. --accent-font-color: #f5f5f5;
  41. --secondary-font-color: #eeeeee;
  42. --margin-padding: 0.5rem;
  43. --border-thickness: 0.2rem;
  44. --border-radius: 0.5rem;
  45. --shadow: 0.6rem 0.6rem 0.1rem 0.1rem rgba(0, 0, 0, 0.2);
  46. --focused-bg-color: rgba(255, 255, 255, 0.1);
  47. }
  48. .container {
  49. padding: var(--margin-padding);
  50. max-width: 600px;
  51. text-align: center;
  52. }
  53. .error-code {
  54. font-size: 4rem;
  55. font-weight: bold;
  56. color: var(--danger-color);
  57. margin-bottom: 1rem;
  58. }
  59. .error-message {
  60. font-size: 1.5rem;
  61. margin-bottom: 2rem;
  62. }
  63. .suggestions {
  64. margin: 2rem 0;
  65. text-align: left;
  66. }
  67. .suggestions-title {
  68. font-weight: bold;
  69. margin-bottom: 0.5rem;
  70. }
  71. .suggestion-list {
  72. list-style: none;
  73. }
  74. .suggestion-item {
  75. background: var(--secondary-bg-color);
  76. border: var(--border-thickness) solid var(--secondary-color);
  77. border-radius: var(--margin-padding);
  78. padding: var(--margin-padding);
  79. margin-bottom: 0.5rem;
  80. cursor: pointer;
  81. }
  82. .suggestion-item:hover {
  83. border-color: var(--accent-color);
  84. transform: scale(1.05);
  85. box-shadow: var(--shadow);
  86. }
  87. .back-home {
  88. display: inline-block;
  89. background: var(--accent-bg-color);
  90. color: var(--accent-font-color);
  91. padding: var(--margin-padding) 1rem;
  92. border: var(--border-thickness) solid var(--accent-color);
  93. border-radius: var(--margin-padding);
  94. font-weight: bold;
  95. margin-top: 1rem;
  96. }
  97. .back-home:hover {
  98. background: var(--accent-color);
  99. color: var(--content-bg-color);
  100. box-shadow: var(--shadow);
  101. }
  102. </style>
  103. </head>
  104. <body>
  105. <div class="container">
  106. <div class="error-code">404</div>
  107. <div class="error-message">页面未找到</div>
  108. <div id="suggestions" class="suggestions">
  109. <div class="suggestions-title">您要找的可能是:</div>
  110. <ul id="suggestion-list" class="suggestion-list"></ul>
  111. </div>
  112. <a href="/" class="back-home">返回首页</a>
  113. </div>
  114. <script>
  115. document.addEventListener("DOMContentLoaded", async () => {
  116. const suggestionList = document.getElementById("suggestion-list");
  117. const suggestionsContainer = document.getElementById("suggestions");
  118. const currentPath = window.location.pathname;
  119. // 加载已安装的应用包列表
  120. async function loadPackages() {
  121. try {
  122. const response = await fetch("/index.json");
  123. const data = await response.json();
  124. return data.packages || [];
  125. } catch (error) {
  126. console.error("加载应用列表失败:", error);
  127. return [];
  128. }
  129. }
  130. // 分析路径并生成建议
  131. function generateSuggestions(packages) {
  132. const suggestions = [];
  133. const pathSegments = currentPath
  134. .split("/")
  135. .filter((segment) => segment.length > 0);
  136. // 如果路径为空,不生成建议
  137. if (pathSegments.length === 0) {
  138. return suggestions;
  139. }
  140. // 尝试匹配包ID
  141. const lastSegment =
  142. pathSegments[pathSegments.length - 1].toLowerCase();
  143. const packageMatches = packages.filter((pkg) =>
  144. pkg.id.toLowerCase().includes(lastSegment)
  145. );
  146. // 添加匹配的包
  147. packageMatches.forEach((pkg) => {
  148. suggestions.push({
  149. text: `${pkg.name} (${pkg.id})`,
  150. url: pkg.location,
  151. });
  152. });
  153. // 如果没有找到匹配,尝试使用第一个路径段
  154. if (suggestions.length === 0 && pathSegments.length > 0) {
  155. const firstSegment = pathSegments[0].toLowerCase();
  156. const firstSegmentMatches = packages.filter((pkg) =>
  157. pkg.id.toLowerCase().includes(firstSegment)
  158. );
  159. firstSegmentMatches.forEach((pkg) => {
  160. suggestions.push({
  161. text: `${pkg.name} (${pkg.id})`,
  162. url: pkg.location,
  163. });
  164. });
  165. }
  166. // 检查是否与包的入口文件匹配
  167. const fullPagePath = window.location.pathname.toLowerCase();
  168. let autoRedirectPackage = null;
  169. packages.forEach((pkg) => {
  170. // 构建可能的入口文件路径
  171. const entryPath = `${pkg.location}/${pkg.id}.html`.toLowerCase();
  172. const indexPath = `${pkg.location}/index.html`.toLowerCase();
  173. // 如果路径与入口文件或索引文件匹配
  174. if (fullPagePath === entryPath || fullPagePath === indexPath) {
  175. // 检查是否已存在相同建议
  176. const exists = suggestions.some((s) => s.url === pkg.location);
  177. if (!exists) {
  178. suggestions.unshift({
  179. text: `您要找的可能是 ${pkg.name} 应用入口`,
  180. url: pkg.location,
  181. });
  182. }
  183. }
  184. // 检查是否版本号不同但包ID相同
  185. const versionPattern = /\/packages\/([^\/]+)\/([0-9.]+)\//;
  186. const match = fullPagePath.match(versionPattern);
  187. if (match) {
  188. const packageId = match[1];
  189. const version = match[2];
  190. if (packageId === pkg.id && version !== pkg.latest_version) {
  191. autoRedirectPackage = pkg;
  192. }
  193. }
  194. });
  195. // 如果找到需要自动跳转的包
  196. if (autoRedirectPackage) {
  197. const countdownElement = document.createElement("div");
  198. countdownElement.id = "countdown";
  199. countdownElement.style.marginTop = "1rem";
  200. countdownElement.style.fontSize = "1.2rem";
  201. countdownElement.style.color = "var(--danger-color)";
  202. document.querySelector(".container").appendChild(countdownElement);
  203. let countdown = 5;
  204. countdownElement.textContent = `将在 ${countdown} 秒后跳转到最新版本 (${autoRedirectPackage.latest_version})...`;
  205. const countdownInterval = setInterval(() => {
  206. countdown--;
  207. countdownElement.textContent = `将在 ${countdown} 秒后跳转到最新版本 (${autoRedirectPackage.latest_version})...`;
  208. if (countdown <= 0) {
  209. clearInterval(countdownInterval);
  210. window.location.href = "../../../" + autoRedirectPackage.location;
  211. }
  212. }, 1000);
  213. }
  214. return suggestions;
  215. }
  216. // 渲染建议列表
  217. function renderSuggestions(suggestions) {
  218. if (suggestions.length === 0) {
  219. suggestionsContainer.style.display = "none";
  220. return;
  221. }
  222. suggestionList.innerHTML = suggestions
  223. .map(
  224. (suggestion) => `
  225. <li class="suggestion-item" onclick="window.location.href='${suggestion.url}'">
  226. ${suggestion.text}
  227. </li>
  228. `
  229. )
  230. .join("");
  231. }
  232. // 主逻辑
  233. const packages = await loadPackages();
  234. const suggestions = generateSuggestions(packages);
  235. renderSuggestions(suggestions);
  236. });
  237. </script>
  238. </body>
  239. </html>