@@ -2201,7 +2201,9 @@ <h3 class="similar-title">
22012201 : game . url ,
22022202 } ) ) ;
22032203 this . render ( ) ;
2204- lucide . createIcons ( ) ;
2204+ setTimeout ( ( ) => {
2205+ lucide . createIcons ( ) ;
2206+ } , 100 ) ;
22052207 showToast (
22062208 "Games Loaded" ,
22072209 `${ this . games . length } games available` ,
@@ -2236,7 +2238,7 @@ <h3 class="similar-title">
22362238 <div class="carousel-card ${ isWide ? "wide" : "square" } " data-id="${
22372239 game . id
22382240 } ">
2239- <img src="${ game . cover } " alt="${ game . name } " loading="lazy ">
2241+ <img src="${ game . cover } " alt="${ game . name } " loading="eager ">
22402242 <div class="carousel-overlay">
22412243 <div class="carousel-name">${ game . name } </div>
22422244 <div class="carousel-meta">by ${
@@ -2475,9 +2477,33 @@ <h2 class="game-title">${game.name}</h2>
24752477
24762478 const newWindow = window . open ( "about:blank" , "_blank" ) ;
24772479 if ( newWindow ) {
2478- newWindow . document . open ( ) ;
2479- newWindow . document . write ( html ) ;
2480- newWindow . document . close ( ) ;
2480+ setTimeout ( ( ) => {
2481+ newWindow . document . open ( ) ;
2482+ newWindow . document . write ( html ) ;
2483+ newWindow . document . close ( ) ;
2484+
2485+ setTimeout ( ( ) => {
2486+ const scripts =
2487+ newWindow . document . querySelectorAll ( "script" ) ;
2488+ scripts . forEach ( ( oldScript ) => {
2489+ const newScript =
2490+ newWindow . document . createElement ( "script" ) ;
2491+ Array . from ( oldScript . attributes ) . forEach ( ( attr ) => {
2492+ newScript . setAttribute ( attr . name , attr . value ) ;
2493+ } ) ;
2494+ if ( oldScript . src ) {
2495+ newScript . src = oldScript . src ;
2496+ } else {
2497+ newScript . textContent = oldScript . textContent ;
2498+ }
2499+ oldScript . parentNode . replaceChild (
2500+ newScript ,
2501+ oldScript
2502+ ) ;
2503+ } ) ;
2504+ } , 100 ) ;
2505+ } , 50 ) ;
2506+
24812507 showToast (
24822508 "Opening Game" ,
24832509 "Game opened in new window" ,
@@ -2501,15 +2527,9 @@ <h2 class="game-title">${game.name}</h2>
25012527 . getElementById ( "reloadBtn" )
25022528 . removeEventListener ( "click" , this . reloadGame ) ;
25032529 document . getElementById ( "reloadBtn" ) . addEventListener ( "click" , ( ) => {
2504- if ( this . isPlaying ) {
2505- const iframe = document . querySelector ( "#gameDisplay iframe" ) ;
2506- if ( iframe && iframe . contentDocument ) {
2507- const html = iframe . contentDocument . documentElement . outerHTML ;
2508- iframe . contentDocument . open ( ) ;
2509- iframe . contentDocument . write ( html ) ;
2510- iframe . contentDocument . close ( ) ;
2511- showToast ( "Reloading" , "Game is reloading..." , "info" ) ;
2512- }
2530+ if ( this . isPlaying && this . currentGame ) {
2531+ this . playGame ( this . currentGame ) ;
2532+ showToast ( "Reloading" , "Game is reloading..." , "info" ) ;
25132533 }
25142534 } ) ;
25152535
@@ -2590,24 +2610,38 @@ <h2 class="game-title">${game.name}</h2>
25902610 "width: 100%; height: 100%; border: none; position: absolute; inset: 0;" ;
25912611 iframe . allow = "fullscreen; autoplay; encrypted-media" ;
25922612 iframe . sandbox =
2593- "allow-scripts allow-same-origin allow-pointer-lock allow-forms" ;
2613+ "allow-scripts allow-same-origin allow-pointer-lock allow-forms allow-modals" ;
2614+
2615+ let loadAttempted = false ;
25942616
25952617 iframe . onload = ( ) => {
2596- document . getElementById ( "fullscreenBtn" ) . disabled = false ;
2597- this . isPlaying = true ;
2598- showToast ( "Ready" , "Game loaded successfully!" , "success" ) ;
2599- lucide . createIcons ( ) ;
2618+ if ( ! loadAttempted ) {
2619+ loadAttempted = true ;
2620+
2621+ setTimeout ( ( ) => {
2622+ try {
2623+ const iframeDoc = iframe . contentWindow . document ;
2624+ iframeDoc . open ( ) ;
2625+ iframeDoc . write ( html ) ;
2626+ iframeDoc . close ( ) ;
2627+
2628+ document . getElementById ( "fullscreenBtn" ) . disabled = false ;
2629+ this . isPlaying = true ;
2630+ showToast ( "Ready" , "Game loaded successfully!" , "success" ) ;
2631+ lucide . createIcons ( ) ;
2632+ } catch ( err ) {
2633+ console . error ( "Failed to write to iframe:" , err ) ;
2634+ throw err ;
2635+ }
2636+ } , 100 ) ;
2637+ }
26002638 } ;
26012639
26022640 iframe . onerror = ( ) => {
26032641 throw new Error ( "Failed to load iframe" ) ;
26042642 } ;
26052643
26062644 gameDisplay . appendChild ( iframe ) ;
2607-
2608- iframe . contentDocument . open ( ) ;
2609- iframe . contentDocument . write ( html ) ;
2610- iframe . contentDocument . close ( ) ;
26112645 } catch ( err ) {
26122646 console . error ( "Failed to load game:" , err ) ;
26132647 showToast ( "Error" , "Failed to load game" , "error" ) ;
0 commit comments