's'
This commit is contained in:
24
app/page.tsx
24
app/page.tsx
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user