site.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. // 填入 apkUrl 即可开放下载;版本信息等字段按需提供。channel 为渠道标注(如「测试版」),可空。
  2. const FMODE_SITE = { apkUrl: 'https://ai.fmode.cn/download/fmode-app-v1.0.apk', version: '1.0', fileSize: '9.9 MB', updatedAt: '2026-11-25', channel: '测试版' };
  3. const header = document.getElementById('header');
  4. const menuToggle = document.getElementById('menuToggle');
  5. const navLinks = document.getElementById('navLinks');
  6. const downloadDialog = document.getElementById('downloadDialog');
  7. const downloadStatus = document.getElementById('downloadStatus');
  8. const releaseMeta = document.getElementById('releaseMeta');
  9. const apkButton = document.getElementById('apkButton');
  10. const setMenuOpen = (open) => {
  11. menuToggle.setAttribute('aria-expanded', String(open));
  12. menuToggle.setAttribute('aria-label', open ? '收起导航' : '展开导航');
  13. menuToggle.innerHTML = '<svg class="icon"><use href="#' + (open ? 'i-close' : 'i-menu') + '"/></svg>';
  14. navLinks.classList.toggle('open', open);
  15. };
  16. menuToggle.addEventListener('click', () => setMenuOpen(menuToggle.getAttribute('aria-expanded') !== 'true'));
  17. navLinks.querySelectorAll('a').forEach((link) => link.addEventListener('click', () => setMenuOpen(false)));
  18. document.addEventListener('keydown', (event) => {
  19. if (event.key === 'Escape' && navLinks.classList.contains('open')) { setMenuOpen(false); menuToggle.focus(); }
  20. });
  21. document.addEventListener('click', (event) => {
  22. if (!event.composedPath().includes(header) && navLinks.classList.contains('open')) setMenuOpen(false);
  23. });
  24. window.matchMedia('(min-width: 761px)').addEventListener('change', (event) => {
  25. if (event.matches) setMenuOpen(false);
  26. });
  27. let scrollQueued = false;
  28. window.addEventListener('scroll', () => {
  29. if (scrollQueued) return;
  30. scrollQueued = true;
  31. requestAnimationFrame(() => { header.classList.toggle('scrolled', window.scrollY > 8); scrollQueued = false; });
  32. }, { passive: true });
  33. const tabButtons = [...document.querySelectorAll('[role="tab"][data-scene]')];
  34. const scenes = [...document.querySelectorAll('[role="tabpanel"]')];
  35. const railItems = [...document.querySelectorAll('[data-rail]')];
  36. function activateScene(name, focusButton = false) {
  37. tabButtons.forEach((tab) => {
  38. const active = tab.dataset.scene === name;
  39. tab.setAttribute('aria-selected', String(active));
  40. tab.tabIndex = active ? 0 : -1;
  41. if (active && focusButton) tab.focus();
  42. });
  43. scenes.forEach((scene) => { scene.hidden = scene.id !== 'scene-' + name; });
  44. railItems.forEach((item) => item.classList.toggle('active', item.dataset.rail === name));
  45. }
  46. tabButtons.forEach((tab, index) => {
  47. tab.addEventListener('click', () => activateScene(tab.dataset.scene));
  48. tab.addEventListener('keydown', (event) => {
  49. if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
  50. event.preventDefault();
  51. let next = index;
  52. if (event.key === 'ArrowRight') next = (index + 1) % tabButtons.length;
  53. if (event.key === 'ArrowLeft') next = (index - 1 + tabButtons.length) % tabButtons.length;
  54. if (event.key === 'Home') next = 0;
  55. if (event.key === 'End') next = tabButtons.length - 1;
  56. activateScene(tabButtons[next].dataset.scene, true);
  57. });
  58. });
  59. const closeButton = document.getElementById('dialogClose');
  60. const confirmButton = document.getElementById('dialogConfirm');
  61. const dialogTitle = document.getElementById('dialogTitle');
  62. const dialogDescription = document.getElementById('dialogDescription');
  63. const dialogQr = document.getElementById('dialogQr');
  64. const dialogDownload = document.querySelector('[data-dialog-download]');
  65. const manualCopy = document.getElementById('manualCopy');
  66. const downloadLink = document.getElementById('downloadLink');
  67. const dialogCopyStatus = document.getElementById('dialogCopyStatus');
  68. let dialogTrigger = null;
  69. let previousOverflow = '';
  70. let qrReady = false;
  71. const isIOS = /iPad|iPhone|iPod/i.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
  72. const isEmbeddedBrowser = /MicroMessenger|\bQQ\//i.test(navigator.userAgent);
  73. function openDownloadDialog(trigger, mode = 'qr') {
  74. setMenuOpen(false);
  75. manualCopy.hidden = true;
  76. dialogCopyStatus.hidden = true;
  77. dialogQr.hidden = !qrReady;
  78. dialogDownload.hidden = !downloadUrl || mode === 'ios' || mode === 'browser';
  79. if (!downloadUrl) {
  80. dialogTitle.textContent = '安装包正在准备中';
  81. dialogDescription.textContent = '下载暂未开放,请稍后再来。正式安装包就绪后,二维码与下载入口会同时开放。';
  82. } else if (mode === 'ios') {
  83. dialogTitle.textContent = '当前提供 Android 版';
  84. dialogDescription.textContent = '此 APK 无法在 iPhone 或 iPad 上安装。你可以保存二维码或复制链接,发送到 Android 设备下载。';
  85. } else if (mode === 'browser') {
  86. dialogTitle.textContent = '请在浏览器中打开下载';
  87. dialogDescription.textContent = '点击右上角「…」,选择「在浏览器打开」,再点击下载。也可以复制链接,粘贴到手机浏览器中打开。';
  88. } else {
  89. dialogTitle.textContent = qrReady ? '扫码,把想法带在身边。' : '直接下载,同样方便。';
  90. dialogDescription.textContent = qrReady ? '使用 Android 手机相机扫码,即可获取安装包。微信扫码后请在浏览器中打开。' : '二维码暂时无法生成,你仍可点击下载或复制安装包链接。';
  91. }
  92. if (!downloadDialog.open) {
  93. dialogTrigger = trigger || document.activeElement;
  94. previousOverflow = document.documentElement.style.overflow;
  95. document.documentElement.style.overflow = 'hidden';
  96. downloadDialog.showModal();
  97. closeButton.focus();
  98. }
  99. }
  100. function closeDownloadDialog() { if (downloadDialog.open) downloadDialog.close(); }
  101. closeButton.addEventListener('click', closeDownloadDialog);
  102. confirmButton.addEventListener('click', closeDownloadDialog);
  103. downloadDialog.addEventListener('close', () => {
  104. document.documentElement.style.overflow = previousOverflow;
  105. if (dialogTrigger?.isConnected) dialogTrigger.focus({ preventScroll: true });
  106. });
  107. downloadDialog.addEventListener('click', (event) => {
  108. const bounds = downloadDialog.getBoundingClientRect();
  109. if (event.target === downloadDialog && (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom)) closeDownloadDialog();
  110. });
  111. function safeDownloadUrl(value) {
  112. if (typeof value !== 'string' || !value.trim()) return null;
  113. try {
  114. const raw = value.trim();
  115. if (/[\u0000-\u0020\\]/.test(raw) || raw.startsWith('//')) return null;
  116. const url = new URL(raw, window.location.href);
  117. if (url.username || url.password) return null;
  118. if (url.protocol === 'https:') return url.href;
  119. const relative = !/^[a-z][a-z\d+.-]*:/i.test(raw);
  120. if (relative && url.origin === window.location.origin && ['http:', 'file:'].includes(url.protocol)) return url.href;
  121. } catch { return null; }
  122. return null;
  123. }
  124. const downloadUrl = safeDownloadUrl(FMODE_SITE.apkUrl);
  125. const downloadButtons = [...document.querySelectorAll('[data-download]')];
  126. downloadButtons.forEach((button) => {
  127. if (downloadUrl) {
  128. button.href = downloadUrl;
  129. button.setAttribute('download', 'Fmode.apk');
  130. }
  131. button.addEventListener('click', (event) => {
  132. const mode = !downloadUrl ? 'unavailable' : isIOS ? 'ios' : isEmbeddedBrowser ? 'browser' : null;
  133. if (mode) { event.preventDefault(); openDownloadDialog(button, mode); }
  134. });
  135. });
  136. document.querySelectorAll('[data-show-qr]').forEach((button) => {
  137. button.addEventListener('click', () => openDownloadDialog(button, isIOS ? 'ios' : 'qr'));
  138. });
  139. function createQrImage(value) {
  140. const qr = qrcodegen.QrCode.encodeText(value, qrcodegen.QrCode.Ecc.MEDIUM);
  141. const scale = 6;
  142. const border = 4;
  143. const image = document.createElement('canvas');
  144. image.width = image.height = (qr.size + border * 2) * scale;
  145. const drawing = image.getContext('2d');
  146. if (!drawing) throw new Error('QR drawing unavailable');
  147. drawing.fillStyle = '#ffffff';
  148. drawing.fillRect(0, 0, image.width, image.height);
  149. drawing.fillStyle = '#080b0c';
  150. for (let y = 0; y < qr.size; y++) {
  151. for (let x = 0; x < qr.size; x++) {
  152. if (qr.getModule(x, y)) drawing.fillRect((x + border) * scale, (y + border) * scale, scale, scale);
  153. }
  154. }
  155. return image.toDataURL('image/png');
  156. }
  157. if (downloadUrl) {
  158. apkButton.removeAttribute('aria-describedby');
  159. downloadStatus.classList.add('ready');
  160. downloadStatus.replaceChildren(document.createElement('i'), document.createTextNode('官方 Android 安装包' + (FMODE_SITE.channel ? '(' + FMODE_SITE.channel + ')' : '') + ' · 下载已开放'));
  161. const metadata = [FMODE_SITE.version && '版本 ' + FMODE_SITE.version, FMODE_SITE.fileSize, FMODE_SITE.updatedAt && '更新于 ' + FMODE_SITE.updatedAt].filter(Boolean);
  162. if (metadata.length) { releaseMeta.hidden = false; releaseMeta.textContent = metadata.join(' · '); }
  163. document.querySelector('[data-release-detail]').textContent = [FMODE_SITE.version && 'v' + FMODE_SITE.version, FMODE_SITE.fileSize, FMODE_SITE.channel].filter(Boolean).join(' · ');
  164. document.querySelector('[data-release-short]').textContent = [FMODE_SITE.version && 'v' + FMODE_SITE.version, FMODE_SITE.channel].filter(Boolean).join(' · ') || 'Android 版';
  165. downloadLink.value = downloadUrl;
  166. document.querySelectorAll('[data-copy-link]').forEach((button) => { button.disabled = false; });
  167. try {
  168. const imageUrl = createQrImage(downloadUrl);
  169. document.querySelectorAll('[data-qr-image]').forEach((image) => { image.src = imageUrl; image.hidden = false; });
  170. document.querySelector('[data-qr-placeholder]').hidden = true;
  171. qrReady = true;
  172. } catch {
  173. document.querySelector('[data-qr-placeholder]').textContent = '二维码暂时不可用';
  174. document.querySelector('.qr-instruction').textContent = '可直接下载,或复制链接到 Android 手机';
  175. }
  176. const heroBadge = document.querySelector('.hero-badge');
  177. heroBadge.replaceChildren(Object.assign(document.createElement('span'), { className: 'tiny-dot' }), document.createTextNode('Android 客户端现已开放下载'));
  178. document.querySelector('.nav-platform').setAttribute('aria-label', 'Android 版现已开放下载');
  179. document.getElementById('faqDownloadAnswer').textContent = '可以。Android 手机可点击「下载 Android 版」直接获取安装包;电脑用户可使用 Android 手机扫描下载二维码。微信或 QQ 内请从右上角菜单选择在浏览器中打开。当前 APK 不支持 iPhone 或 iPad 安装。';
  180. if (isIOS || isEmbeddedBrowser) document.querySelector('[data-install-hint]').textContent = isIOS ? '你正在使用 iOS 设备,当前 APK 仅支持 Android。可将二维码或链接分享给 Android 设备。' : '微信 / QQ 内可能无法直接下载。请点击右上角「…」,选择在浏览器中打开。';
  181. } else {
  182. document.querySelector('[data-qr-placeholder]').textContent = '下载开放后显示二维码';
  183. document.querySelector('.qr-instruction').textContent = '安装包准备中,请稍后再来';
  184. document.querySelector('[data-release-short]').textContent = '即将开放';
  185. document.querySelector('[data-install-hint]').hidden = true;
  186. document.querySelector('.nav-platform').setAttribute('aria-label', 'Android 版即将开放下载');
  187. }
  188. let toastTimer;
  189. function showDownloadToast(message) {
  190. const toast = document.getElementById('downloadToast');
  191. clearTimeout(toastTimer);
  192. toast.textContent = message;
  193. toast.classList.add('visible');
  194. toastTimer = setTimeout(() => toast.classList.remove('visible'), 3200);
  195. }
  196. document.querySelectorAll('[data-copy-link]').forEach((button) => button.addEventListener('click', async () => {
  197. if (!downloadUrl) return;
  198. try {
  199. if (!navigator.clipboard?.writeText) throw new Error('Clipboard unavailable');
  200. await navigator.clipboard.writeText(downloadUrl);
  201. const message = '下载链接已复制,可发送到 Android 手机';
  202. if (downloadDialog.open) {
  203. dialogCopyStatus.textContent = message;
  204. dialogCopyStatus.hidden = false;
  205. } else showDownloadToast(message);
  206. } catch {
  207. openDownloadDialog(button);
  208. manualCopy.hidden = false;
  209. downloadLink.focus();
  210. downloadLink.select();
  211. showDownloadToast('请长按或选中下载链接,手动复制');
  212. }
  213. }));
  214. const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
  215. if ('IntersectionObserver' in window && !reduceMotion.matches) {
  216. const observer = new IntersectionObserver((entries) => {
  217. entries.forEach((entry) => { if (!entry.isIntersecting) return; entry.target.classList.add('is-visible'); observer.unobserve(entry.target); });
  218. }, { threshold: 0.12, rootMargin: '0px 0px -35px 0px' });
  219. document.querySelectorAll('.feature-card, .start-grid article, .download-card, .faq-intro').forEach((item) => { item.classList.add('reveal'); observer.observe(item); });
  220. }
  221. const canvas = document.getElementById('atmosphere');
  222. const context = canvas.getContext('2d', { alpha: true });
  223. let particles = [];
  224. let animationFrame = 0;
  225. let canvasWidth = 0;
  226. let canvasHeight = 0;
  227. function resizeCanvas() {
  228. if (!context) return;
  229. const bounds = canvas.getBoundingClientRect();
  230. const ratio = Math.min(window.devicePixelRatio || 1, 1.5);
  231. canvasWidth = bounds.width;
  232. canvasHeight = bounds.height;
  233. canvas.width = Math.round(bounds.width * ratio);
  234. canvas.height = Math.round(bounds.height * ratio);
  235. context.setTransform(ratio, 0, 0, ratio, 0, 0);
  236. const count = Math.min(66, Math.max(28, Math.round(bounds.width * bounds.height / 18000)));
  237. particles = Array.from({ length: count }, () => ({ x: Math.random() * canvasWidth, y: Math.random() * canvasHeight, radius: Math.random() * 1.05 + .28, opacity: Math.random() * .38 + .09, speed: Math.random() * .13 + .035, phase: Math.random() * Math.PI * 2 }));
  238. }
  239. function drawAtmosphere() {
  240. if (!context || document.hidden || reduceMotion.matches) { animationFrame = 0; return; }
  241. context.clearRect(0, 0, canvasWidth, canvasHeight);
  242. const time = performance.now() * .00045;
  243. particles.forEach((particle) => {
  244. const twinkle = (Math.sin(time + particle.phase) + 1) * .5;
  245. context.beginPath();
  246. context.fillStyle = 'rgba(199, 255, 211, ' + particle.opacity * (.55 + twinkle * .45) + ')';
  247. context.arc(particle.x, particle.y, particle.radius, 0, Math.PI * 2);
  248. context.fill();
  249. particle.y -= particle.speed;
  250. if (particle.y < -2) { particle.y = canvasHeight + 2; particle.x = Math.random() * canvasWidth; }
  251. });
  252. animationFrame = window.requestAnimationFrame(drawAtmosphere);
  253. }
  254. function startAtmosphere() { if (!context || reduceMotion.matches || document.hidden || animationFrame) return; animationFrame = window.requestAnimationFrame(drawAtmosphere); }
  255. function stopAtmosphere() { if (animationFrame) window.cancelAnimationFrame(animationFrame); animationFrame = 0; }
  256. resizeCanvas();
  257. startAtmosphere();
  258. window.addEventListener('resize', () => { resizeCanvas(); startAtmosphere(); }, { passive: true });
  259. document.addEventListener('visibilitychange', () => document.hidden ? stopAtmosphere() : startAtmosphere());
  260. reduceMotion.addEventListener?.('change', () => reduceMotion.matches ? stopAtmosphere() : startAtmosphere());