刷新回子页面二修:不看 referrer,改看用户是否点过才离开(usernav);从别的应用回首页、后退照旧算回首页;防来回跳;ugc 关时不记;广场标签方案 A 压回三行 (v26110641)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
deploy
2026-11-07 06:13:04 +00:00
parent c71517dc78
commit 82b9864392
129 changed files with 161 additions and 141 deletions

View File

@@ -3,7 +3,7 @@
(function () {
'use strict';
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
var VER = '26110640';
var VER = '26110641';
const $ = (s, c) => (c || document).querySelector(s);
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
@@ -207,14 +207,22 @@
function resumeSub() {
try {
if (/[?&](wh|wc|go|demo)=/.test(location.search) || hashParam('norestore')) return false;
const ref = document.referrer || '';
if (ref.indexOf(location.origin + '/') === 0 || isBackToThisPage()) { localStorage.removeItem(SUB_KEY); 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) {}
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; }
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;
const go = function () {
console.log('[resume] 回到上次停的子页面:', sub.u);
try { sessionStorage.setItem('mmbox.subback', String(Date.now())); } catch (e) {}
location.replace(withIdentity(sub.u) + location.hash); /* 身份 query + 原 hash 都带上(子页面 hash/query 双读) */
};
const oid = hashParam('openid');