Commit c38d00e 1 parent 3107d66 commit c38d00e Copy full SHA for c38d00e
File tree 1 file changed +10
-8
lines changed
1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -5,24 +5,26 @@ export type RequestBody = {
5
5
tab ?: string
6
6
active ?: boolean
7
7
params ?: Record < string , string >
8
- singleton ?: boolean
8
+ singleton ?: boolean | string [ ]
9
9
}
10
10
11
11
const handler : PlasmoMessaging . MessageHandler < RequestBody , chrome . tabs . Tab > = async ( req , res ) => {
12
12
const { url, tab, active } = req . body
13
13
const queryString = req . body . params ? `?${ new URLSearchParams ( req . body . params ) . toString ( ) } ` : ''
14
14
const fullUrl = tab ? chrome . runtime . getURL ( `/tabs/${ tab } .html${ queryString } ` ) : url + queryString
15
+ const pathUrl = ( tab ? chrome . runtime . getURL ( `/tabs/${ tab } .html` ) : url ) + '*'
15
16
if ( req . body . singleton ) {
16
- const tabs = await chrome . tabs . query ( { url : fullUrl } )
17
- if ( tabs . length ) {
18
- const tab = tabs [ 0 ]
19
- await chrome . tabs . update ( tab . id , { active : true } )
20
- res . send ( tab )
17
+ const tabs = await chrome . tabs . query ( { url : typeof req . body . singleton === 'boolean' ? fullUrl : pathUrl } )
18
+ const tab = tabs . find ( tab =>
19
+ typeof req . body . singleton === 'boolean' ||
20
+ req . body . singleton . some ( param => new URL ( tab . url ) . searchParams . get ( param ) === req . body . params [ param ] )
21
+ )
22
+ if ( tab ) {
23
+ res . send ( await chrome . tabs . update ( tab . id , { active : true } ) )
21
24
return
22
25
}
23
26
}
24
- const result = await chrome . tabs . create ( { url : fullUrl , active } )
25
- res . send ( result )
27
+ res . send ( await chrome . tabs . create ( { url : fullUrl , active } ) )
26
28
}
27
29
28
30
You can’t perform that action at this time.
0 commit comments