刷新回子页面:防来回跳只拦同一页 5 秒内 (v26110642)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
deploy
2026-11-07 06:17:48 +00:00
parent 82b9864392
commit 7d413a5375
4 changed files with 12 additions and 11 deletions

View File

@@ -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');

View File

@@ -70,7 +70,7 @@
function repOf(c, me) { return { p: c.parent, n: me ? '我' : (c.nickname || '孕妈'), me: me, to: c.parentName, t: c.text, ts: c.at, st: me ? c.status : '' }; }
function load() {
if (loading || SIM) return; loading = true;
fetch('guangchang/cm.json?v=26110641').then(function (r) { return r.json(); }).then(function (j) {
fetch('guangchang/cm.json?v=26110642').then(function (r) { return r.json(); }).then(function (j) {
var PP = j.p;
SIM = (j.c[PID] || []).map(function (c, k) {
var p = PP[c[0]];