mirror of
https://github.com/Zippland/Snap-Solver.git
synced 2026-02-23 16:39:19 +08:00
删除计数器
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -123,3 +123,8 @@ Thumbs.db
|
|||||||
|
|
||||||
# Optional eslint cache
|
# Optional eslint cache
|
||||||
.eslintcache
|
.eslintcache
|
||||||
|
|
||||||
|
# 应用特定文件
|
||||||
|
config/update_info.json
|
||||||
|
.venv/
|
||||||
|
venv/
|
||||||
@@ -6,16 +6,12 @@ class UIManager {
|
|||||||
this.closeSettings = document.getElementById('closeSettings');
|
this.closeSettings = document.getElementById('closeSettings');
|
||||||
this.themeToggle = document.getElementById('themeToggle');
|
this.themeToggle = document.getElementById('themeToggle');
|
||||||
this.toastContainer = document.getElementById('toastContainer');
|
this.toastContainer = document.getElementById('toastContainer');
|
||||||
this.visitorCountElement = document.getElementById('visitorCount');
|
|
||||||
|
|
||||||
// Check for preferred color scheme
|
// Check for preferred color scheme
|
||||||
this.checkPreferredColorScheme();
|
this.checkPreferredColorScheme();
|
||||||
|
|
||||||
// Initialize event listeners
|
// Initialize event listeners
|
||||||
this.setupEventListeners();
|
this.setupEventListeners();
|
||||||
|
|
||||||
// Initialize visitor counter
|
|
||||||
this.initVisitorCounter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkPreferredColorScheme() {
|
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
|
// Export for use in other modules
|
||||||
|
|||||||
@@ -274,10 +274,6 @@
|
|||||||
<div class="footer-content">
|
<div class="footer-content">
|
||||||
<div class="footer-text">
|
<div class="footer-text">
|
||||||
<span>© 2024 Snap-Solver <span class="version-badge">v<span id="currentVersion">{{ update_info.current_version }}</span></span></span>
|
<span>© 2024 Snap-Solver <span class="version-badge">v<span id="currentVersion">{{ update_info.current_version }}</span></span></span>
|
||||||
<div class="user-counter">
|
|
||||||
<span>访问</span>
|
|
||||||
<div id="visitorCount" class="counter-number">--</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="footer-links">
|
<div class="footer-links">
|
||||||
<a href="https://github.com/Zippland/Snap-Solver/" target="_blank" class="footer-link">
|
<a href="https://github.com/Zippland/Snap-Solver/" target="_blank" class="footer-link">
|
||||||
|
|||||||
Reference in New Issue
Block a user