File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -336,9 +336,25 @@ for (const releaseCardMedia of releaseCardMediaElements) {
336336}
337337
338338// target="_blank"
339+ /** @type {HTMLAnchorElement[] } */
339340const anchors = Array . from (
340341 document . querySelector ( "main .release-container" ) . querySelectorAll ( "a" ) ,
341342) ;
342343for ( const anchor of anchors ) {
343- anchor . target = anchor . target || "_blank" ;
344+ try {
345+ const anchorUrl = new URL ( anchor . href ) ;
346+ const isInternalLink =
347+ anchorUrl . protocol === window . location . protocol &&
348+ anchorUrl . host === window . location . host &&
349+ anchorUrl . port === window . location . port &&
350+ anchorUrl . pathname === window . location . pathname &&
351+ anchorUrl . hash . startsWith ( "#" ) ;
352+ if ( ! isInternalLink ) {
353+ anchor . target = "_blank" ;
354+ }
355+ } catch ( err ) {
356+ const newErr = new Error ( "Error while setting anchor target to blank." ) ;
357+ newErr . cause = err ;
358+ console . error ( newErr ) ;
359+ }
344360}
You can’t perform that action at this time.
0 commit comments