diff --git a/public/games-external/common/index.htm b/public/games-external/common/index.htm index 0862930f..fcc74bab 100644 --- a/public/games-external/common/index.htm +++ b/public/games-external/common/index.htm @@ -1,30 +1,29 @@ - + - - - - - + + + + Full Screen iFrame - + - + - - + - - - - - \ No newline at end of file + + diff --git a/themes/game/components/GameEmbed.js b/themes/game/components/GameEmbed.js index eeef8fd0..ec1b79c3 100644 --- a/themes/game/components/GameEmbed.js +++ b/themes/game/components/GameEmbed.js @@ -19,35 +19,57 @@ export default function GameEmbed({ post, siteInfo }) { // 提示用户在新窗口打开 const [tipNewWindow, setTipNewWindow] = useState(newWindow) - const [url, setUrl] = useState(originUrl) const [loading, setLoading] = useState(true) /** - * 新窗口中打开 + * 新窗口中打开游戏。 + * 并且在回到此页面后后刷新iframe,尝试重新加载iframe */ const openInNewWindow = () => { + // 关闭提示框 setTipNewWindow(false) - setTimeout(function () { - setUrl('') - setUrl(originUrl) - }, 10000) // 10000毫秒 = 10秒 + // 添加监听器 + document.addEventListener('visibilitychange', handleVisibilityChange) + + // 定义监听器函数 + function handleVisibilityChange() { + if (document.visibilityState === 'hidden') { + // console.log("用户切换到了其他标签页"); + } else { + // console.log("用户回到了当前页面"); + // 刷新网页 + reloadIframe() + // 移除监听器 + document.removeEventListener('visibilitychange', handleVisibilityChange) + } + } + } + + /** + * 隐藏提示框 + */ + const hiddenTips = () => { + setTipNewWindow(false) + } + + function reloadIframe() { + var iframe = document.getElementById('game-wrapper') + iframe.contentWindow.location.reload() + } + + // 定义一个函数来处理iframe加载成功事件 + function iframeLoaded() { + if (game) { + setLoading(false) + } } - // 将当前游戏加入到最近游玩 useEffect(() => { - // 切换游戏时更新 - setUrl(originUrl) + // 是否弹窗提示新网页打开 setTipNewWindow(newWindow) const iframe = document.getElementById('game-wrapper') - // 定义一个函数来处理iframe加载成功事件 - function iframeLoaded() { - if (game) { - setLoading(false) - } - } - // 绑定加载事件 if (iframe?.attachEvent) { iframe?.attachEvent('onload', iframeLoaded) @@ -67,11 +89,11 @@ export default function GameEmbed({ post, siteInfo }) { game?.title || '' } - Play ${game?.title || ''} on ${siteConfig('TITLE')}` } - }, [game]) + }, [post]) return (
+ className={`${originUrl ? '' : 'hidden'} bg-black w-full xl:h-[calc(100vh-8rem)] h-screen rounded-md relative`}> {/* 移动端返回主页按钮 */}
-
+
-
-
+
If the game fails to load, please try accessing the{' '} source webpage @@ -153,12 +171,12 @@ export default function GameEmbed({ post, siteInfo }) { )}