@@ -4,47 +4,48 @@ import { logger } from "@/utils/logger";
4
4
5
5
export const implantScript = ( ) => {
6
6
/** RUN INJECT SCRIPT IN DOCUMENT START **/
7
- if ( process . env . PLATFORM === "chromium" ) {
8
- // https://bugs.chromium.org/p/chromium/issues/detail?id=634381
9
- // https://stackoverflow.com/questions/75495191/chrome-extension-manifest-v3-how-to-use-window-addeventlistener
10
- if ( cross . scripting && cross . scripting . registerContentScripts ) {
11
- logger . info ( "Register Inject Scripts By Scripting API" ) ;
12
- // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/registerContentScripts
13
- cross . scripting
14
- . registerContentScripts ( [
15
- {
16
- matches : [ ...URL_MATCH ] ,
17
- runAt : "document_start" ,
18
- world : "MAIN" ,
19
- allFrames : true ,
20
- js : [ process . env . INJECT_FILE + ".js" ] ,
21
- id : process . env . INJECT_FILE ,
22
- } ,
23
- ] )
24
- . catch ( err => {
25
- logger . warning ( "Register Inject Scripts Failed" , err ) ;
26
- } ) ;
27
- } else {
28
- logger . info ( "Register Inject Scripts By Tabs API" ) ;
29
- // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/onUpdated
30
- cross . tabs . onUpdated . addListener ( ( _ , changeInfo , tab ) => {
31
- if ( changeInfo . status == "loading" ) {
32
- const tabId = tab && tab . id ;
33
- const tabURL = tab && tab . url ;
34
- if ( tabURL && ! URL_MATCH . some ( match => new RegExp ( match ) . test ( tabURL ) ) ) {
35
- return void 0 ;
36
- }
37
- if ( tabId && cross . scripting ) {
38
- cross . scripting . executeScript ( {
39
- target : { tabId : tabId , allFrames : true } ,
40
- files : [ process . env . INJECT_FILE + ".js" ] ,
41
- injectImmediately : true ,
42
- } ) ;
43
- }
44
- }
7
+ // #IFDEF CHROMIUM
8
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=634381
9
+ // https://stackoverflow.com/questions/75495191/chrome-extension-manifest-v3-how-to-use-window-addeventlistener
10
+ if ( cross . scripting && cross . scripting . registerContentScripts ) {
11
+ logger . info ( "Register Inject Scripts By Scripting API" ) ;
12
+ // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/registerContentScripts
13
+ cross . scripting
14
+ . registerContentScripts ( [
15
+ {
16
+ matches : [ ...URL_MATCH ] ,
17
+ runAt : "document_start" ,
18
+ world : "MAIN" ,
19
+ allFrames : true ,
20
+ js : [ process . env . INJECT_FILE + ".js" ] ,
21
+ id : process . env . INJECT_FILE ,
22
+ } ,
23
+ ] )
24
+ . catch ( err => {
25
+ logger . warning ( "Register Inject Scripts Failed" , err ) ;
45
26
} ) ;
46
- }
47
27
} else {
48
- logger . info ( "Register Inject Scripts By Inline Code" ) ;
28
+ logger . info ( "Register Inject Scripts By Tabs API" ) ;
29
+ // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/onUpdated
30
+ cross . tabs . onUpdated . addListener ( ( _ , changeInfo , tab ) => {
31
+ if ( changeInfo . status == "loading" ) {
32
+ const tabId = tab && tab . id ;
33
+ const tabURL = tab && tab . url ;
34
+ if ( tabURL && ! URL_MATCH . some ( match => new RegExp ( match ) . test ( tabURL ) ) ) {
35
+ return void 0 ;
36
+ }
37
+ if ( tabId && cross . scripting ) {
38
+ cross . scripting . executeScript ( {
39
+ target : { tabId : tabId , allFrames : true } ,
40
+ files : [ process . env . INJECT_FILE + ".js" ] ,
41
+ injectImmediately : true ,
42
+ } ) ;
43
+ }
44
+ }
45
+ } ) ;
49
46
}
47
+ // #ENDIF
48
+ // #IFDEF GECKO
49
+ logger . info ( "Register Inject Scripts By Content Script Inline Code" ) ;
50
+ // #ENDIF
50
51
} ;
0 commit comments