/* eslint-disable @next/next/no-img-element */ import { Draggable } from '@/components/Draggable' import { siteConfig } from '@/lib/config' import { deepClone } from '@/lib/utils' import Link from 'next/link' import { useEffect, useState } from 'react' import DownloadButton from './DownloadButton' import FullScreenButton from './FullScreenButton' /** * 嵌入游戏 * @param {*} param0 * @returns */ export default function GameEmbed({ post, siteInfo }) { const game = deepClone(post) const newWindow = game?.ext?.new_window || false const originUrl = game?.ext?.href // 提示用户在新窗口打开 const [tipNewWindow, setTipNewWindow] = useState(newWindow) const [url, setUrl] = useState(originUrl) const [loading, setLoading] = useState(true) /** * 新窗口中打开 */ const openInNewWindow = () => { setTipNewWindow(false) setTimeout(function () { setUrl('') setUrl(originUrl) }, 10000) // 10000毫秒 = 10秒 } // 将当前游戏加入到最近游玩 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) } else if (iframe) { iframe.onload = iframeLoaded } // 更改iFrame的title if ( document ?.getElementById('game-wrapper') ?.contentDocument.querySelector('title')?.textContent ) { document .getElementById('game-wrapper') .contentDocument.querySelector('title').textContent = `${ game?.title || '' } - Play ${game?.title || ''} on ${siteConfig('TITLE')}` } }, [game]) return (
{/* 移动端返回主页按钮 */}
{' '} { document.querySelector('.game-info').scrollIntoView({ behavior: 'smooth', block: 'end', inline: 'nearest' }) }}> {/* Title首字母 */} {siteInfo?.title?.charAt(0)}
{/* 提示框新窗口打开 */} {tipNewWindow && (
If the game fails to load, please try accessing the{' '} source webpage .
)} {/* Loading遮罩 */} {loading && (

{siteInfo?.title || siteConfig('TITLE')}

{siteInfo?.description || siteConfig('DESCRIPTION')}

{/* 游戏封面图 */} {game?.pageCoverThumbnail && ( )}
)}