site.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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-23', 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. let scrollQueued = false;
  22. window.addEventListener('scroll', () => {
  23. if (scrollQueued) return;
  24. scrollQueued = true;
  25. requestAnimationFrame(() => { header.classList.toggle('scrolled', window.scrollY > 8); scrollQueued = false; });
  26. }, { passive: true });
  27. const tabButtons = [...document.querySelectorAll('[role="tab"][data-scene]')];
  28. const scenes = [...document.querySelectorAll('[role="tabpanel"]')];
  29. const railItems = [...document.querySelectorAll('[data-rail]')];
  30. function activateScene(name, focusButton = false) {
  31. tabButtons.forEach((tab) => {
  32. const active = tab.dataset.scene === name;
  33. tab.setAttribute('aria-selected', String(active));
  34. tab.tabIndex = active ? 0 : -1;
  35. if (active && focusButton) tab.focus();
  36. });
  37. scenes.forEach((scene) => { scene.hidden = scene.id !== 'scene-' + name; });
  38. railItems.forEach((item) => item.classList.toggle('active', item.dataset.rail === name));
  39. }
  40. tabButtons.forEach((tab, index) => {
  41. tab.addEventListener('click', () => activateScene(tab.dataset.scene));
  42. tab.addEventListener('keydown', (event) => {
  43. if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
  44. event.preventDefault();
  45. let next = index;
  46. if (event.key === 'ArrowRight') next = (index + 1) % tabButtons.length;
  47. if (event.key === 'ArrowLeft') next = (index - 1 + tabButtons.length) % tabButtons.length;
  48. if (event.key === 'Home') next = 0;
  49. if (event.key === 'End') next = tabButtons.length - 1;
  50. activateScene(tabButtons[next].dataset.scene, true);
  51. });
  52. });
  53. const closeButton = document.getElementById('dialogClose');
  54. const confirmButton = document.getElementById('dialogConfirm');
  55. function closeDownloadDialog() { if (downloadDialog.open) downloadDialog.close(); apkButton.focus(); }
  56. closeButton.addEventListener('click', closeDownloadDialog);
  57. confirmButton.addEventListener('click', closeDownloadDialog);
  58. downloadDialog.addEventListener('click', (event) => { if (event.target === downloadDialog) closeDownloadDialog(); });
  59. function safeDownloadUrl(value) {
  60. if (!value) return null;
  61. try {
  62. const url = new URL(value, window.location.href);
  63. if (url.protocol === 'https:' || (url.protocol === 'file:' && value.startsWith('./'))) return url.href;
  64. } catch { return null; }
  65. return null;
  66. }
  67. const downloadUrl = safeDownloadUrl(FMODE_SITE.apkUrl);
  68. if (downloadUrl) {
  69. apkButton.href = downloadUrl;
  70. apkButton.removeAttribute('aria-describedby');
  71. apkButton.setAttribute('download', 'Fmode.apk');
  72. document.getElementById('downloadLabel').textContent = '下载 Android 安装包';
  73. downloadStatus.classList.add('ready');
  74. downloadStatus.innerHTML = '<i></i>官方 Android 安装包' + (FMODE_SITE.channel ? '(' + FMODE_SITE.channel + ')' : '') + ' · 下载已开放';
  75. const metadata = [FMODE_SITE.version && '版本 ' + FMODE_SITE.version, FMODE_SITE.fileSize, FMODE_SITE.updatedAt && '更新于 ' + FMODE_SITE.updatedAt].filter(Boolean);
  76. if (metadata.length) { releaseMeta.hidden = false; releaseMeta.textContent = metadata.join(' · '); }
  77. const heroBadge = document.querySelector('.hero-badge');
  78. heroBadge.replaceChildren(Object.assign(document.createElement('span'), { className: 'tiny-dot' }), document.createTextNode('Android 客户端现已开放下载'));
  79. document.querySelector('.nav-platform').setAttribute('aria-label', 'Android 版现已开放下载');
  80. document.getElementById('faqDownloadAnswer').textContent = 'Android 客户端现已开放下载。使用手机访问本页,点击下载按钮即可获取安装包;如在电脑访问,可将下载后的 APK 传至 Android 设备安装。';
  81. } else {
  82. apkButton.addEventListener('click', (event) => { event.preventDefault(); downloadDialog.showModal(); closeButton.focus(); });
  83. }
  84. const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
  85. if ('IntersectionObserver' in window && !reduceMotion.matches) {
  86. const observer = new IntersectionObserver((entries) => {
  87. entries.forEach((entry) => { if (!entry.isIntersecting) return; entry.target.classList.add('is-visible'); observer.unobserve(entry.target); });
  88. }, { threshold: 0.12, rootMargin: '0px 0px -35px 0px' });
  89. document.querySelectorAll('.feature-card, .start-grid article, .download-card, .faq-intro').forEach((item) => { item.classList.add('reveal'); observer.observe(item); });
  90. }
  91. const canvas = document.getElementById('atmosphere');
  92. const context = canvas.getContext('2d', { alpha: true });
  93. let particles = [];
  94. let animationFrame = 0;
  95. let canvasWidth = 0;
  96. let canvasHeight = 0;
  97. function resizeCanvas() {
  98. if (!context) return;
  99. const bounds = canvas.getBoundingClientRect();
  100. const ratio = Math.min(window.devicePixelRatio || 1, 1.5);
  101. canvasWidth = bounds.width;
  102. canvasHeight = bounds.height;
  103. canvas.width = Math.round(bounds.width * ratio);
  104. canvas.height = Math.round(bounds.height * ratio);
  105. context.setTransform(ratio, 0, 0, ratio, 0, 0);
  106. const count = Math.min(66, Math.max(28, Math.round(bounds.width * bounds.height / 18000)));
  107. 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 }));
  108. }
  109. function drawAtmosphere() {
  110. if (!context || document.hidden || reduceMotion.matches) { animationFrame = 0; return; }
  111. context.clearRect(0, 0, canvasWidth, canvasHeight);
  112. const time = performance.now() * .00045;
  113. particles.forEach((particle) => {
  114. const twinkle = (Math.sin(time + particle.phase) + 1) * .5;
  115. context.beginPath();
  116. context.fillStyle = 'rgba(199, 255, 211, ' + particle.opacity * (.55 + twinkle * .45) + ')';
  117. context.arc(particle.x, particle.y, particle.radius, 0, Math.PI * 2);
  118. context.fill();
  119. particle.y -= particle.speed;
  120. if (particle.y < -2) { particle.y = canvasHeight + 2; particle.x = Math.random() * canvasWidth; }
  121. });
  122. animationFrame = window.requestAnimationFrame(drawAtmosphere);
  123. }
  124. function startAtmosphere() { if (!context || reduceMotion.matches || document.hidden || animationFrame) return; animationFrame = window.requestAnimationFrame(drawAtmosphere); }
  125. function stopAtmosphere() { if (animationFrame) window.cancelAnimationFrame(animationFrame); animationFrame = 0; }
  126. resizeCanvas();
  127. startAtmosphere();
  128. window.addEventListener('resize', () => { resizeCanvas(); startAtmosphere(); }, { passive: true });
  129. document.addEventListener('visibilitychange', () => document.hidden ? stopAtmosphere() : startAtmosphere());
  130. reduceMotion.addEventListener?.('change', () => reduceMotion.matches ? stopAtmosphere() : startAtmosphere());