@@ -385,20 +385,21 @@ document.addEventListener("DOMContentLoaded", () => {
385385
386386 // Handle _blank links: same domain navigates in-app, cross-domain opens new window
387387 if ( target === "_blank" ) {
388- e . preventDefault ( ) ;
389- e . stopImmediatePropagation ( ) ;
390-
391388 if ( isSameDomain ( absoluteUrl ) ) {
392- window . location . href = absoluteUrl ;
393- } else {
394- const newWindow = originalWindowOpen . call (
395- window ,
396- absoluteUrl ,
397- "_blank" ,
398- "width=1200,height=800,scrollbars=yes,resizable=yes" ,
399- ) ;
400- if ( ! newWindow ) handleExternalLink ( absoluteUrl ) ;
389+ // For same-domain links, let the browser/SPA handle it naturally
390+ // This prevents full page reload in SPA apps like Discord
391+ return ;
401392 }
393+
394+ e . preventDefault ( ) ;
395+ e . stopImmediatePropagation ( ) ;
396+ const newWindow = originalWindowOpen . call (
397+ window ,
398+ absoluteUrl ,
399+ "_blank" ,
400+ "width=1200,height=800,scrollbars=yes,resizable=yes" ,
401+ ) ;
402+ if ( ! newWindow ) handleExternalLink ( absoluteUrl ) ;
402403 return ;
403404 }
404405
@@ -448,39 +449,24 @@ document.addEventListener("DOMContentLoaded", () => {
448449 // Rewrite the window.open function.
449450 const originalWindowOpen = window . open ;
450451 window . open = function ( url , name , specs ) {
451- // Apple login and google login
452452 if ( name === "AppleAuthentication" ) {
453- //do nothing
454- } else if (
455- specs &&
456- ( specs . includes ( "height=" ) || specs . includes ( "width=" ) )
457- ) {
458- location . href = url ;
459- } else {
453+ return originalWindowOpen . call ( window , url , name , specs ) ;
454+ }
455+
456+ try {
460457 const baseUrl = window . location . origin + window . location . pathname ;
461458 const hrefUrl = new URL ( url , baseUrl ) ;
462459 const absoluteUrl = hrefUrl . href ;
463460
464- // Apply same domain logic as anchor links
465- if ( isSameDomain ( absoluteUrl ) ) {
466- // Same domain: navigate in app or open new window based on specs
467- if ( name === "_blank" || ! name ) {
468- return originalWindowOpen . call (
469- window ,
470- absoluteUrl ,
471- "_blank" ,
472- "width=1200,height=800,scrollbars=yes,resizable=yes" ,
473- ) ;
474- } else {
475- location . href = absoluteUrl ;
476- }
477- } else {
478- // Cross domain: open in external browser
461+ if ( ! isSameDomain ( absoluteUrl ) ) {
479462 handleExternalLink ( absoluteUrl ) ;
463+ return null ;
480464 }
465+
466+ return originalWindowOpen . call ( window , absoluteUrl , name , specs ) ;
467+ } catch ( error ) {
468+ return originalWindowOpen . call ( window , url , name , specs ) ;
481469 }
482- // Call the original window.open function to maintain its normal functionality.
483- return originalWindowOpen . call ( window , url , name , specs ) ;
484470 } ;
485471
486472 // Set the default zoom, There are problems with Loop without using try-catch.
0 commit comments