刷新回子页面:防来回跳只拦同一页 5 秒内 (v26110642)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
13
js/app.js
13
js/app.js
@@ -3,7 +3,7 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
|
||||
var VER = '26110641';
|
||||
var VER = '26110642';
|
||||
const $ = (s, c) => (c || document).querySelector(s);
|
||||
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
|
||||
|
||||
@@ -209,20 +209,21 @@
|
||||
if (/[?&](wh|wc|go|demo)=/.test(location.search) || hashParam('norestore')) return false;
|
||||
/* 11-07 二修:不再看 referrer —— 宿主回前台 / 刷新是在原页面里直接换地址,referrer 也是子页面。
|
||||
改为:子页面里用户刚点过东西才离开(last-sub.js 记 sessionStorage mmbox.usernav)或后退 = 用户自己回首页 → 清记录;
|
||||
刚恢复过一次又回到首页且不是用户点的(比如那页自己又跳回来)→ 也不再恢复,防来回跳。 */
|
||||
let un = 0, rs = 0;
|
||||
try { un = +sessionStorage.getItem('mmbox.usernav') || 0; rs = +sessionStorage.getItem('mmbox.subback') || 0; sessionStorage.removeItem('mmbox.usernav'); } catch (e) {}
|
||||
5 秒内刚把人送回同一页、它又回到首页且不是用户点的(那页自己跳回来)→ 不再恢复,防来回跳。 */
|
||||
let un = 0, rs = null;
|
||||
try { un = +sessionStorage.getItem('mmbox.usernav') || 0; rs = JSON.parse(sessionStorage.getItem('mmbox.subback') || 'null'); sessionStorage.removeItem('mmbox.usernav'); } catch (e) {}
|
||||
let nt = '';
|
||||
try { const nv = performance.getEntriesByType && performance.getEntriesByType('navigation')[0]; nt = nv ? nv.type : ''; } catch (e) {}
|
||||
const ref = document.referrer || '', fromApp = ref.indexOf(location.origin + '/') === 0 && ref.indexOf(location.origin + homeDir()) !== 0; /* 从别的应用(不在首页仓里)回来:那边没有 usernav 标记,照旧按 referrer 算用户回首页 */
|
||||
if (Date.now() - un < 8000 || nt === 'back_forward' || fromApp || Date.now() - rs < 15000) { localStorage.removeItem(SUB_KEY); return false; }
|
||||
if (Date.now() - un < 8000 || nt === 'back_forward' || fromApp) { localStorage.removeItem(SUB_KEY); return false; }
|
||||
const inMp = window.__wxjs_environment === 'miniprogram' || /miniProgram/i.test(navigator.userAgent);
|
||||
if (!inMp) return false;
|
||||
const sub = JSON.parse(localStorage.getItem(SUB_KEY) || 'null');
|
||||
if (!sub || !sub.u || sub.h !== homeDir() || sub.u.indexOf(homeDir()) !== 0 || Date.now() - sub.at > 7 * 864e5) return false;
|
||||
if (rs && rs.u === sub.u && Date.now() - rs.at < 5000) { localStorage.removeItem(SUB_KEY); return false; } /* 5 秒前刚送回这一页、它自己又回了首页:别来回跳 */
|
||||
const go = function () {
|
||||
console.log('[resume] 回到上次停的子页面:', sub.u);
|
||||
try { sessionStorage.setItem('mmbox.subback', String(Date.now())); } catch (e) {}
|
||||
try { sessionStorage.setItem('mmbox.subback', JSON.stringify({ u: sub.u, at: Date.now() })); } catch (e) {}
|
||||
location.replace(withIdentity(sub.u) + location.hash); /* 身份 query + 原 hash 都带上(子页面 hash/query 双读) */
|
||||
};
|
||||
const oid = hashParam('openid');
|
||||
|
||||
Reference in New Issue
Block a user