刷新回子页面二修:不看 referrer,改看用户是否点过才离开(usernav);从别的应用回首页、后退照旧算回首页;防来回跳;ugc 关时不记;广场标签方案 A 压回三行 (v26110641)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user