刷新回子页面二修:不看 referrer,改看用户是否点过才离开(usernav);从别的应用回首页、后退照旧算回首页;防来回跳;ugc 关时不记;广场标签方案 A 压回三行 (v26110641)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
14
js/app.js
14
js/app.js
@@ -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');
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
var DROP = /^(openid|unionid|t|_v|phone|nickname|avatar|__no_identity)$/;
|
||||
function save() {
|
||||
try {
|
||||
/* 广场 / 测一测关着(ugc.js data-guard 会把页面送回首页):不记,免得首页又送回来 */
|
||||
if (document.documentElement.classList.contains('ugc-off') && document.querySelector('script[data-guard]')) { localStorage.removeItem(K); return; }
|
||||
var q = new URLSearchParams(location.search), k = [];
|
||||
q.forEach(function (v, n) { if (DROP.test(n)) k.push(n); });
|
||||
k.forEach(function (n) { q.delete(n); });
|
||||
@@ -28,6 +30,15 @@
|
||||
addEventListener('popstate', save);
|
||||
addEventListener('pageshow', function (e) { if (e.persisted) save(); });
|
||||
|
||||
/* 11-07 二修:用户自己点了按钮才离开这页(返回 / 返回首页 / 底栏…)→ 记一个「用户导航」标记,首页见到它就不恢复、清记录。
|
||||
小程序回前台 / 刷新时宿主是直接把 web-view 地址换成首页,页面里没有任何点按 → 没有标记 → 首页把人送回这一页。
|
||||
(第一次修法看 document.referrer 是否同源:宿主在原页面里换地址,referrer 也是子页面,被误当成用户回首页、把记录清了。) */
|
||||
var act = 0;
|
||||
['pointerdown', 'touchstart', 'click', 'keydown'].forEach(function (ev) { addEventListener(ev, function () { act = Date.now(); }, true); });
|
||||
addEventListener('pagehide', function () {
|
||||
try { if (Date.now() - act < 2500) sessionStorage.setItem('mmbox.usernav', String(Date.now())); } catch (e) {}
|
||||
});
|
||||
|
||||
/* 从别的应用后退回来 → 清 last_app */
|
||||
try {
|
||||
var nav = performance.getEntriesByType && performance.getEntriesByType('navigation')[0];
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
}).catch(function () {});
|
||||
|
||||
function apply(v) { on = !!v; window.__mbUgc = on; de.classList.toggle('ugc-off', !on); }
|
||||
function goHome() { location.replace(home + (location.hash || '')); }
|
||||
function goHome() { try { localStorage.removeItem('mmbox.lastsub.v1'); } catch (e) {} location.replace(home + (location.hash || '')); } /* 11-07 别让首页「刷新回子页面」又送回来 */
|
||||
apply(on);
|
||||
if (guard && !on) de.style.visibility = 'hidden'; /* 还不知道开没开:先别露内容,免得关着时闪一下 */
|
||||
|
||||
|
||||
@@ -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=26110640').then(function (r) { return r.json(); }).then(function (j) {
|
||||
fetch('guangchang/cm.json?v=26110641').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]];
|
||||
|
||||
Reference in New Issue
Block a user