From 4361c68fa71b9e7ff91cd688658cba637973b936 Mon Sep 17 00:00:00 2001 From: Zylan Date: Sat, 29 Mar 2025 15:23:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=AE=A1=E6=95=B0=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 7 +++- static/js/ui.js | 81 -------------------------------------------- templates/index.html | 4 --- 3 files changed, 6 insertions(+), 86 deletions(-) diff --git a/.gitignore b/.gitignore index 58a026d..d663b3c 100644 --- a/.gitignore +++ b/.gitignore @@ -122,4 +122,9 @@ Thumbs.db *.tgz # Optional eslint cache -.eslintcache \ No newline at end of file +.eslintcache + +# 应用特定文件 +config/update_info.json +.venv/ +venv/ \ No newline at end of file diff --git a/static/js/ui.js b/static/js/ui.js index 2e29bb8..301a307 100644 --- a/static/js/ui.js +++ b/static/js/ui.js @@ -6,16 +6,12 @@ class UIManager { this.closeSettings = document.getElementById('closeSettings'); this.themeToggle = document.getElementById('themeToggle'); this.toastContainer = document.getElementById('toastContainer'); - this.visitorCountElement = document.getElementById('visitorCount'); // Check for preferred color scheme this.checkPreferredColorScheme(); // Initialize event listeners this.setupEventListeners(); - - // Initialize visitor counter - this.initVisitorCounter(); } checkPreferredColorScheme() { @@ -96,83 +92,6 @@ class UIManager { } }); } - - initVisitorCounter() { - try { - // 获取本地存储的计数 - let localCount = parseInt(localStorage.getItem('visitorCount') || '0'); - - // 检查是否是今天第一次访问 - const lastVisitDate = localStorage.getItem('lastVisitDate'); - const today = new Date().toDateString(); - - if (lastVisitDate !== today) { - // 今天第一次访问,增加计数 - localCount++; - localStorage.setItem('visitorCount', localCount.toString()); - localStorage.setItem('lastVisitDate', today); - - // 尝试向CountAPI发送计数增加请求 - this.incrementCountAPI(); - } - - // 显示计数 - this.updateVisitorCountDisplay(localCount); - - // 从CountAPI获取全局计数 - this.fetchGlobalCount(); - } catch (error) { - console.error('访问计数器初始化失败:', error); - this.visitorCountElement.textContent = '0'; - } - } - - incrementCountAPI() { - // 使用免费的CountAPI服务来增加计数 - // 注意:这个免费API有使用限制,生产环境可能需要更可靠的服务 - fetch('https://api.countapi.xyz/hit/snap-solver-app/visits') - .catch(error => console.error('无法更新全局计数:', error)); - } - - fetchGlobalCount() { - // 获取全局计数 - fetch('https://api.countapi.xyz/get/snap-solver-app/visits') - .then(response => response.json()) - .then(data => { - // 将全局计数与本地计数取较大值显示 - const localCount = parseInt(localStorage.getItem('visitorCount') || '0'); - const globalCount = data.value || 0; - const displayCount = Math.max(localCount, globalCount); - - this.updateVisitorCountDisplay(displayCount); - - // 如果全局计数更大,则更新本地存储 - if (globalCount > localCount) { - localStorage.setItem('visitorCount', globalCount.toString()); - } - }) - .catch(error => { - console.error('无法获取全局计数:', error); - // 如果全局计数获取失败,至少显示本地计数 - const localCount = parseInt(localStorage.getItem('visitorCount') || '0'); - this.updateVisitorCountDisplay(localCount); - }); - } - - updateVisitorCountDisplay(count) { - if (this.visitorCountElement) { - // 低调显示,超过1000显示为1k+,超过10000显示为10k+等 - if (count >= 10000) { - const kCount = Math.floor(count / 1000); - this.visitorCountElement.textContent = `${kCount}k+`; - } else if (count >= 1000) { - const kCount = Math.floor(count / 100) / 10; - this.visitorCountElement.textContent = `${kCount}k+`; - } else { - this.visitorCountElement.textContent = count.toString(); - } - } - } } // Export for use in other modules diff --git a/templates/index.html b/templates/index.html index 28db3f2..b9a7f1e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -274,10 +274,6 @@