diff --git a/css/style.css b/css/style.css index 4ae0231..214a30e 100644 --- a/css/style.css +++ b/css/style.css @@ -910,3 +910,6 @@ html, body { overflow-x: hidden; } .qq-later:hover{color:#a9b8d6} @keyframes qqPop{from{transform:scale(.94) translateY(6px);opacity:0}to{transform:none;opacity:1}} @keyframes qqIn{from{opacity:0}to{opacity:1}} + +.qq-chip{margin-left:10px;padding:6px 12px;border-radius:999px;border:1px solid rgba(255,190,90,.45);background:rgba(255,176,64,.12);color:#ffcf8a;font-size:12.5px;cursor:pointer} +.qq-chip:hover{background:rgba(255,176,64,.2)} diff --git a/js/qq-group.js b/js/qq-group.js index cf9abe6..766ecce 100644 --- a/js/qq-group.js +++ b/js/qq-group.js @@ -72,6 +72,7 @@ const later = el('button', 'qq-later', '以后再说') later.addEventListener('click', () => { + dismissed = true try { localStorage.setItem(SEEN, '1') } catch {} close(mask) }) @@ -84,16 +85,42 @@ document.body.append(mask) } + let dismissed = false + function maybeShow(user) { - if (!user || user.qqClaim) return - let seen = false - try { seen = localStorage.getItem(SEEN) === '1' } catch {} - // 每次登录都提醒一次,但 30 分钟内不再重复弹 - const last = Number(localStorage.getItem(SEEN + '.at') || 0) - if (seen && Date.now() - last < 30 * 60 * 1000) return - try { localStorage.setItem(SEEN + '.at', String(Date.now())) } catch {} - setTimeout(() => show(user), 600) + if (!user || user.qqClaim) { dropChip(); return } + if (dismissed) return + dismissed = false + setTimeout(() => { if (!document.querySelector('.qq-mask')) show(user) }, 500) + addChip() } + /* 顶栏常驻入口:万一弹窗被系统/缓存挡掉,也能点出来 */ + function addChip() { + if (document.getElementById('qqChip')) return + const who = document.getElementById('who') + if (!who) return + const a = document.createElement('button') + a.id = 'qqChip' + a.className = 'qq-chip' + a.textContent = '🎁 加群领 500' + a.addEventListener('click', () => { + const u = DB.auth.state ? DB.auth.state.user : null + show(u || {}) + }) + who.append(a) + } + + function dropChip() { + const n = document.getElementById('qqChip') + if (n) n.remove() + } + + document.addEventListener('DOMContentLoaded', () => { + const u = window.DB && DB.auth && DB.auth.state ? DB.auth.state.user : null + if (u) maybeShow(u) + }) + if (window.DB && DB.auth && DB.auth.onChange) DB.auth.onChange((u) => { if (u) maybeShow(u); else dropChip() }) + DB.qq = { show, maybeShow, url: GROUP_URL } })() diff --git a/server.mjs b/server.mjs index 1452ba6..9500ab0 100644 --- a/server.mjs +++ b/server.mjs @@ -128,7 +128,7 @@ async function serveStatic(req, res, pathname) { } res.writeHead(200, { 'content-type': MIME[extname(file).toLowerCase()] || 'application/octet-stream', - 'cache-control': rel.endsWith('.html') ? 'no-cache' : 'public, max-age=3600', + 'cache-control': /\.(html|js|css)$/.test(rel) ? 'no-cache, must-revalidate' : 'public, max-age=86400', etag, 'x-content-type-options': 'nosniff' })