create-packer 1.45.9 → 1.45.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { CONTENT_MATCHES } from '@/shared/content'
|
|
1
|
+
import { CONTENT_MATCHES, contentMessage } from '@/shared/content'
|
|
2
2
|
import { Common } from './modules'
|
|
3
3
|
|
|
4
4
|
export default defineContentScript({
|
|
5
5
|
runAt: 'document_idle',
|
|
6
6
|
matches: CONTENT_MATCHES,
|
|
7
7
|
main: () => {
|
|
8
|
+
contentMessage.onMessage('CONNECT', () => true)
|
|
8
9
|
Common.insert()
|
|
9
10
|
}
|
|
10
11
|
})
|
|
@@ -2,28 +2,53 @@ import { defineExtensionMessaging } from '@webext-core/messaging'
|
|
|
2
2
|
import { CONTENT_MATCHES } from './constant'
|
|
3
3
|
|
|
4
4
|
export type messageType = {
|
|
5
|
-
|
|
5
|
+
CONNECT: () => true
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export const { sendMessage, onMessage } = defineExtensionMessaging<messageType>()
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
|
|
10
|
+
export async function connectableTabs(tabQueryInfo?: chrome.tabs.QueryInfo) {
|
|
11
|
+
const tabs = await chrome.tabs.query({
|
|
12
|
+
...tabQueryInfo,
|
|
13
|
+
url: tabQueryInfo?.url || CONTENT_MATCHES
|
|
14
|
+
})
|
|
15
|
+
const result = await Promise.allSettled(
|
|
15
16
|
tabs.map(tab => {
|
|
16
|
-
return sendMessage(
|
|
17
|
+
return sendMessage('CONNECT', void 0, { tabId: tab.id! }).then(res => ({
|
|
18
|
+
data: res,
|
|
19
|
+
tab
|
|
20
|
+
}))
|
|
17
21
|
})
|
|
18
22
|
)
|
|
19
|
-
return result
|
|
23
|
+
return result?.filter(o => o.status === 'fulfilled').map(o => o.value.tab)
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
export async function
|
|
26
|
+
export async function sendToContent<A extends keyof messageType>(
|
|
23
27
|
action: A,
|
|
24
|
-
|
|
28
|
+
options: {
|
|
29
|
+
data?: Parameters<messageType[A]>[0]
|
|
30
|
+
url?: string[]
|
|
31
|
+
target: 'first' | 'last' | 'all' | 'current'
|
|
32
|
+
}
|
|
25
33
|
) {
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
let tabs = await connectableTabs({ url: options?.url })
|
|
35
|
+
switch (options.target) {
|
|
36
|
+
case 'current':
|
|
37
|
+
tabs = tabs.filter(tab => tab.active)
|
|
38
|
+
break
|
|
39
|
+
case 'first':
|
|
40
|
+
tabs = tabs.slice(0, 1)
|
|
41
|
+
break
|
|
42
|
+
case 'last':
|
|
43
|
+
tabs = tabs.slice(-1)
|
|
44
|
+
break
|
|
45
|
+
default:
|
|
46
|
+
break
|
|
47
|
+
}
|
|
48
|
+
const result = await Promise.all(
|
|
49
|
+
tabs.map(tab => {
|
|
50
|
+
return sendMessage(action, options.data as never, { tabId: tab.id! })
|
|
51
|
+
})
|
|
52
|
+
)
|
|
28
53
|
return result
|
|
29
54
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as popupMessage from './message'
|