first commit

This commit is contained in:
baozaotumao2025
2026-07-18 21:10:39 +08:00
commit 1b90e552a5
91 changed files with 9056 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
const key = 'safety-last-activity-at'
const throttleMs = 30_000
export const activity = {
get: () => Number(localStorage.getItem(key) || 0),
record(force = false) {
const now = Date.now()
if (force || now - this.get() >= throttleMs) localStorage.setItem(key, String(now))
},
clear: () => localStorage.removeItem(key),
start(checkRefresh: () => void) {
const onActivity = () => { this.record(); checkRefresh() }
const onVisible = () => { if (document.visibilityState === 'visible') checkRefresh() }
const events = ['click', 'keydown', 'touchstart'] as const
events.forEach((event) => window.addEventListener(event, onActivity, { passive: true }))
window.addEventListener('popstate', onActivity)
document.addEventListener('visibilitychange', onVisible)
return () => {
events.forEach((event) => window.removeEventListener(event, onActivity))
window.removeEventListener('popstate', onActivity)
document.removeEventListener('visibilitychange', onVisible)
}
},
}