| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- // 填入 apkUrl 即可开放下载;版本信息等字段按需提供。channel 为渠道标注(如「测试版」),可空。
- 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: '测试版' };
- const header = document.getElementById('header');
- const menuToggle = document.getElementById('menuToggle');
- const navLinks = document.getElementById('navLinks');
- const downloadDialog = document.getElementById('downloadDialog');
- const downloadStatus = document.getElementById('downloadStatus');
- const releaseMeta = document.getElementById('releaseMeta');
- const apkButton = document.getElementById('apkButton');
- const setMenuOpen = (open) => {
- menuToggle.setAttribute('aria-expanded', String(open));
- menuToggle.setAttribute('aria-label', open ? '收起导航' : '展开导航');
- menuToggle.innerHTML = '<svg class="icon"><use href="#' + (open ? 'i-close' : 'i-menu') + '"/></svg>';
- navLinks.classList.toggle('open', open);
- };
- menuToggle.addEventListener('click', () => setMenuOpen(menuToggle.getAttribute('aria-expanded') !== 'true'));
- navLinks.querySelectorAll('a').forEach((link) => link.addEventListener('click', () => setMenuOpen(false)));
- document.addEventListener('keydown', (event) => {
- if (event.key === 'Escape' && navLinks.classList.contains('open')) { setMenuOpen(false); menuToggle.focus(); }
- });
- document.addEventListener('click', (event) => {
- if (!event.composedPath().includes(header) && navLinks.classList.contains('open')) setMenuOpen(false);
- });
- window.matchMedia('(min-width: 761px)').addEventListener('change', (event) => {
- if (event.matches) setMenuOpen(false);
- });
- let scrollQueued = false;
- window.addEventListener('scroll', () => {
- if (scrollQueued) return;
- scrollQueued = true;
- requestAnimationFrame(() => { header.classList.toggle('scrolled', window.scrollY > 8); scrollQueued = false; });
- }, { passive: true });
- const tabButtons = [...document.querySelectorAll('[role="tab"][data-scene]')];
- const scenes = [...document.querySelectorAll('[role="tabpanel"]')];
- const railItems = [...document.querySelectorAll('[data-rail]')];
- function activateScene(name, focusButton = false) {
- tabButtons.forEach((tab) => {
- const active = tab.dataset.scene === name;
- tab.setAttribute('aria-selected', String(active));
- tab.tabIndex = active ? 0 : -1;
- if (active && focusButton) tab.focus();
- });
- scenes.forEach((scene) => { scene.hidden = scene.id !== 'scene-' + name; });
- railItems.forEach((item) => item.classList.toggle('active', item.dataset.rail === name));
- }
- tabButtons.forEach((tab, index) => {
- tab.addEventListener('click', () => activateScene(tab.dataset.scene));
- tab.addEventListener('keydown', (event) => {
- if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
- event.preventDefault();
- let next = index;
- if (event.key === 'ArrowRight') next = (index + 1) % tabButtons.length;
- if (event.key === 'ArrowLeft') next = (index - 1 + tabButtons.length) % tabButtons.length;
- if (event.key === 'Home') next = 0;
- if (event.key === 'End') next = tabButtons.length - 1;
- activateScene(tabButtons[next].dataset.scene, true);
- });
- });
- const closeButton = document.getElementById('dialogClose');
- const confirmButton = document.getElementById('dialogConfirm');
- const dialogTitle = document.getElementById('dialogTitle');
- const dialogDescription = document.getElementById('dialogDescription');
- const dialogQr = document.getElementById('dialogQr');
- const dialogDownload = document.querySelector('[data-dialog-download]');
- const manualCopy = document.getElementById('manualCopy');
- const downloadLink = document.getElementById('downloadLink');
- const dialogCopyStatus = document.getElementById('dialogCopyStatus');
- let dialogTrigger = null;
- let previousOverflow = '';
- let qrReady = false;
- const isIOS = /iPad|iPhone|iPod/i.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
- const isEmbeddedBrowser = /MicroMessenger|\bQQ\//i.test(navigator.userAgent);
- function openDownloadDialog(trigger, mode = 'qr') {
- setMenuOpen(false);
- manualCopy.hidden = true;
- dialogCopyStatus.hidden = true;
- dialogQr.hidden = !qrReady;
- dialogDownload.hidden = !downloadUrl || mode === 'ios' || mode === 'browser';
- if (!downloadUrl) {
- dialogTitle.textContent = '安装包正在准备中';
- dialogDescription.textContent = '下载暂未开放,请稍后再来。正式安装包就绪后,二维码与下载入口会同时开放。';
- } else if (mode === 'ios') {
- dialogTitle.textContent = '当前提供 Android 版';
- dialogDescription.textContent = '此 APK 无法在 iPhone 或 iPad 上安装。你可以保存二维码或复制链接,发送到 Android 设备下载。';
- } else if (mode === 'browser') {
- dialogTitle.textContent = '请在浏览器中打开下载';
- dialogDescription.textContent = '点击右上角「…」,选择「在浏览器打开」,再点击下载。也可以复制链接,粘贴到手机浏览器中打开。';
- } else {
- dialogTitle.textContent = qrReady ? '扫码,把想法带在身边。' : '直接下载,同样方便。';
- dialogDescription.textContent = qrReady ? '使用 Android 手机相机扫码,即可获取安装包。微信扫码后请在浏览器中打开。' : '二维码暂时无法生成,你仍可点击下载或复制安装包链接。';
- }
- if (!downloadDialog.open) {
- dialogTrigger = trigger || document.activeElement;
- previousOverflow = document.documentElement.style.overflow;
- document.documentElement.style.overflow = 'hidden';
- downloadDialog.showModal();
- closeButton.focus();
- }
- }
- function closeDownloadDialog() { if (downloadDialog.open) downloadDialog.close(); }
- closeButton.addEventListener('click', closeDownloadDialog);
- confirmButton.addEventListener('click', closeDownloadDialog);
- downloadDialog.addEventListener('close', () => {
- document.documentElement.style.overflow = previousOverflow;
- if (dialogTrigger?.isConnected) dialogTrigger.focus({ preventScroll: true });
- });
- downloadDialog.addEventListener('click', (event) => {
- const bounds = downloadDialog.getBoundingClientRect();
- if (event.target === downloadDialog && (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom)) closeDownloadDialog();
- });
- function safeDownloadUrl(value) {
- if (typeof value !== 'string' || !value.trim()) return null;
- try {
- const raw = value.trim();
- if (/[\u0000-\u0020\\]/.test(raw) || raw.startsWith('//')) return null;
- const url = new URL(raw, window.location.href);
- if (url.username || url.password) return null;
- if (url.protocol === 'https:') return url.href;
- const relative = !/^[a-z][a-z\d+.-]*:/i.test(raw);
- if (relative && url.origin === window.location.origin && ['http:', 'file:'].includes(url.protocol)) return url.href;
- } catch { return null; }
- return null;
- }
- const downloadUrl = safeDownloadUrl(FMODE_SITE.apkUrl);
- const downloadButtons = [...document.querySelectorAll('[data-download]')];
- downloadButtons.forEach((button) => {
- if (downloadUrl) {
- button.href = downloadUrl;
- button.setAttribute('download', 'Fmode.apk');
- }
- button.addEventListener('click', (event) => {
- const mode = !downloadUrl ? 'unavailable' : isIOS ? 'ios' : isEmbeddedBrowser ? 'browser' : null;
- if (mode) { event.preventDefault(); openDownloadDialog(button, mode); }
- });
- });
- document.querySelectorAll('[data-show-qr]').forEach((button) => {
- button.addEventListener('click', () => openDownloadDialog(button, isIOS ? 'ios' : 'qr'));
- });
- function createQrImage(value) {
- const qr = qrcodegen.QrCode.encodeText(value, qrcodegen.QrCode.Ecc.MEDIUM);
- const scale = 6;
- const border = 4;
- const image = document.createElement('canvas');
- image.width = image.height = (qr.size + border * 2) * scale;
- const drawing = image.getContext('2d');
- if (!drawing) throw new Error('QR drawing unavailable');
- drawing.fillStyle = '#ffffff';
- drawing.fillRect(0, 0, image.width, image.height);
- drawing.fillStyle = '#080b0c';
- for (let y = 0; y < qr.size; y++) {
- for (let x = 0; x < qr.size; x++) {
- if (qr.getModule(x, y)) drawing.fillRect((x + border) * scale, (y + border) * scale, scale, scale);
- }
- }
- return image.toDataURL('image/png');
- }
- if (downloadUrl) {
- apkButton.removeAttribute('aria-describedby');
- downloadStatus.classList.add('ready');
- downloadStatus.replaceChildren(document.createElement('i'), document.createTextNode('官方 Android 安装包' + (FMODE_SITE.channel ? '(' + FMODE_SITE.channel + ')' : '') + ' · 下载已开放'));
- const metadata = [FMODE_SITE.version && '版本 ' + FMODE_SITE.version, FMODE_SITE.fileSize, FMODE_SITE.updatedAt && '更新于 ' + FMODE_SITE.updatedAt].filter(Boolean);
- if (metadata.length) { releaseMeta.hidden = false; releaseMeta.textContent = metadata.join(' · '); }
- document.querySelector('[data-release-detail]').textContent = [FMODE_SITE.version && 'v' + FMODE_SITE.version, FMODE_SITE.fileSize, FMODE_SITE.channel].filter(Boolean).join(' · ');
- document.querySelector('[data-release-short]').textContent = [FMODE_SITE.version && 'v' + FMODE_SITE.version, FMODE_SITE.channel].filter(Boolean).join(' · ') || 'Android 版';
- downloadLink.value = downloadUrl;
- document.querySelectorAll('[data-copy-link]').forEach((button) => { button.disabled = false; });
- try {
- const imageUrl = createQrImage(downloadUrl);
- document.querySelectorAll('[data-qr-image]').forEach((image) => { image.src = imageUrl; image.hidden = false; });
- document.querySelector('[data-qr-placeholder]').hidden = true;
- qrReady = true;
- } catch {
- document.querySelector('[data-qr-placeholder]').textContent = '二维码暂时不可用';
- document.querySelector('.qr-instruction').textContent = '可直接下载,或复制链接到 Android 手机';
- }
- const heroBadge = document.querySelector('.hero-badge');
- heroBadge.replaceChildren(Object.assign(document.createElement('span'), { className: 'tiny-dot' }), document.createTextNode('Android 客户端现已开放下载'));
- document.querySelector('.nav-platform').setAttribute('aria-label', 'Android 版现已开放下载');
- document.getElementById('faqDownloadAnswer').textContent = '可以。Android 手机可点击「下载 Android 版」直接获取安装包;电脑用户可使用 Android 手机扫描下载二维码。微信或 QQ 内请从右上角菜单选择在浏览器中打开。当前 APK 不支持 iPhone 或 iPad 安装。';
- if (isIOS || isEmbeddedBrowser) document.querySelector('[data-install-hint]').textContent = isIOS ? '你正在使用 iOS 设备,当前 APK 仅支持 Android。可将二维码或链接分享给 Android 设备。' : '微信 / QQ 内可能无法直接下载。请点击右上角「…」,选择在浏览器中打开。';
- } else {
- document.querySelector('[data-qr-placeholder]').textContent = '下载开放后显示二维码';
- document.querySelector('.qr-instruction').textContent = '安装包准备中,请稍后再来';
- document.querySelector('[data-release-short]').textContent = '即将开放';
- document.querySelector('[data-install-hint]').hidden = true;
- document.querySelector('.nav-platform').setAttribute('aria-label', 'Android 版即将开放下载');
- }
- let toastTimer;
- function showDownloadToast(message) {
- const toast = document.getElementById('downloadToast');
- clearTimeout(toastTimer);
- toast.textContent = message;
- toast.classList.add('visible');
- toastTimer = setTimeout(() => toast.classList.remove('visible'), 3200);
- }
- document.querySelectorAll('[data-copy-link]').forEach((button) => button.addEventListener('click', async () => {
- if (!downloadUrl) return;
- try {
- if (!navigator.clipboard?.writeText) throw new Error('Clipboard unavailable');
- await navigator.clipboard.writeText(downloadUrl);
- const message = '下载链接已复制,可发送到 Android 手机';
- if (downloadDialog.open) {
- dialogCopyStatus.textContent = message;
- dialogCopyStatus.hidden = false;
- } else showDownloadToast(message);
- } catch {
- openDownloadDialog(button);
- manualCopy.hidden = false;
- downloadLink.focus();
- downloadLink.select();
- showDownloadToast('请长按或选中下载链接,手动复制');
- }
- }));
- const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
- if ('IntersectionObserver' in window && !reduceMotion.matches) {
- const observer = new IntersectionObserver((entries) => {
- entries.forEach((entry) => { if (!entry.isIntersecting) return; entry.target.classList.add('is-visible'); observer.unobserve(entry.target); });
- }, { threshold: 0.12, rootMargin: '0px 0px -35px 0px' });
- document.querySelectorAll('.feature-card, .start-grid article, .download-card, .faq-intro').forEach((item) => { item.classList.add('reveal'); observer.observe(item); });
- }
- const canvas = document.getElementById('atmosphere');
- const context = canvas.getContext('2d', { alpha: true });
- let particles = [];
- let animationFrame = 0;
- let canvasWidth = 0;
- let canvasHeight = 0;
- function resizeCanvas() {
- if (!context) return;
- const bounds = canvas.getBoundingClientRect();
- const ratio = Math.min(window.devicePixelRatio || 1, 1.5);
- canvasWidth = bounds.width;
- canvasHeight = bounds.height;
- canvas.width = Math.round(bounds.width * ratio);
- canvas.height = Math.round(bounds.height * ratio);
- context.setTransform(ratio, 0, 0, ratio, 0, 0);
- const count = Math.min(66, Math.max(28, Math.round(bounds.width * bounds.height / 18000)));
- 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 }));
- }
- function drawAtmosphere() {
- if (!context || document.hidden || reduceMotion.matches) { animationFrame = 0; return; }
- context.clearRect(0, 0, canvasWidth, canvasHeight);
- const time = performance.now() * .00045;
- particles.forEach((particle) => {
- const twinkle = (Math.sin(time + particle.phase) + 1) * .5;
- context.beginPath();
- context.fillStyle = 'rgba(199, 255, 211, ' + particle.opacity * (.55 + twinkle * .45) + ')';
- context.arc(particle.x, particle.y, particle.radius, 0, Math.PI * 2);
- context.fill();
- particle.y -= particle.speed;
- if (particle.y < -2) { particle.y = canvasHeight + 2; particle.x = Math.random() * canvasWidth; }
- });
- animationFrame = window.requestAnimationFrame(drawAtmosphere);
- }
- function startAtmosphere() { if (!context || reduceMotion.matches || document.hidden || animationFrame) return; animationFrame = window.requestAnimationFrame(drawAtmosphere); }
- function stopAtmosphere() { if (animationFrame) window.cancelAnimationFrame(animationFrame); animationFrame = 0; }
- resizeCanvas();
- startAtmosphere();
- window.addEventListener('resize', () => { resizeCanvas(); startAtmosphere(); }, { passive: true });
- document.addEventListener('visibilitychange', () => document.hidden ? stopAtmosphere() : startAtmosphere());
- reduceMotion.addEventListener?.('change', () => reduceMotion.matches ? stopAtmosphere() : startAtmosphere());
|