@@ -13,24 +13,25 @@ const view = new View(store)
1313
1414console . log ( `${ ID } (v${ VERSION } )` )
1515
16- function tryGetUrl ( element : Element ) : string | null {
16+ function tryGetUrls ( element : Element ) : string [ ] | undefined {
1717 const selection = window . getSelection ( ) ?. toString ( )
1818 if ( selection ) {
1919 const urls = Array . from ( getUrls ( selection ) )
20- return urls . length > 0
21- ? urls [ 0 ]
22- // : selection
23- : null
20+ if ( urls . length > 0 ) {
21+ return urls
22+ }
2423 }
2524
2625 const link = element . closest ( 'a' )
27- return link ?. href || null
26+ if ( link && link . href ) {
27+ return [ link . href ]
28+ }
2829}
2930
3031document . addEventListener ( 'contextmenu' , ( e : MouseEvent ) => {
31- const href = tryGetUrl ( e . target as Element ) ?. trim ( )
32+ const urls = tryGetUrls ( e . target as Element )
3233
33- if ( ! href ) {
34+ if ( ! urls ) {
3435 return
3536 }
3637
@@ -40,13 +41,13 @@ document.addEventListener('contextmenu', (e: MouseEvent) => {
4041 timer = CLEANED
4142 if ( store . trigger === 'double' ) {
4243 e . preventDefault ( )
43- GM_openInTab ( href , { active : store . active } )
44+ urls . forEach ( url => GM_openInTab ( url , { active : store . active } ) )
4445 }
4546 return
4647 }
4748
4849 if ( import . meta. env . DEV ) {
49- console . log ( `open ${ href } in ${ store . active ? 'foreground' : 'background' } mode` )
50+ console . log ( `open ${ urls } in ${ store . active ? 'foreground' : 'background' } mode` )
5051 }
5152
5253 if ( store . trigger === 'single' ) {
@@ -57,7 +58,7 @@ document.addEventListener('contextmenu', (e: MouseEvent) => {
5758 // single click
5859 timer = CLEANED
5960 if ( store . trigger === 'single' ) {
60- GM_openInTab ( href , { active : store . active } )
61+ urls . forEach ( url => GM_openInTab ( url , { active : store . active } ) )
6162 }
6263 } , THRESHOLD )
6364} )
0 commit comments