This commit is contained in:
eric
2026-03-10 08:39:35 -05:00
parent 053482e9f3
commit 9b4467d4f7

View File

@@ -270,6 +270,30 @@ export default function Home() {
init();
}, [clearAllStorage, getOrCreateUserId, checkPaymentFromPB, savePaidType, saveUserName]);
// 页面重新可见或从 bfcache 恢复时检查支付状态(从 /paid 返回、切换标签页、后退等)
useEffect(() => {
const syncFromStorage = () => {
const localType = getStorage("paidType");
const localUserName = getStorage("userName");
if (localType && localUserName && !paidType) {
setPaidType(localType);
setUserName(localUserName);
}
};
const onVisible = () => syncFromStorage();
const onPageShow = (e: PageTransitionEvent) => {
if (e.persisted) syncFromStorage(); // 从 bfcache 恢复
};
if (typeof document !== "undefined" && document.addEventListener) {
document.addEventListener("visibilitychange", onVisible);
window.addEventListener("pageshow", onPageShow);
return () => {
document.removeEventListener("visibilitychange", onVisible);
window.removeEventListener("pageshow", onPageShow);
};
}
}, [paidType]);
marked.setOptions({ breaks: true, gfm: true });
return (