@@ -20,44 +20,15 @@ function createMainWorldExecutor(
2020 requiredUrls ,
2121 gmInfo
2222) {
23-
24-
25- const MAX_RETRIES = 30 ;
26- const RETRY_INTERVAL = 100 ;
27-
2823 function waitForGMBridge ( worldType , callback ) {
29- let retries = 0 ;
30-
31- function check ( ) {
32- const hasRequiredObjects =
33- window . GMBridge ?. ResourceManager &&
34- window . GMBridge ?. GMAPIRegistry &&
35- window . GMBridge ?. ExternalScriptLoader &&
36- window . GMBridge ?. executeUserScriptWithDependencies ;
37-
38- if ( hasRequiredObjects ) {
39- callback ( ) ;
40- return ;
41- }
42-
43- if ( retries < MAX_RETRIES ) {
44- retries ++ ;
45- setTimeout ( check , RETRY_INTERVAL ) ;
46- } else {
47- console . error (
48- `CodeTweak: Timed out waiting for core script to load for script '${ scriptId } '${ worldType ? ` in ${ worldType } world` : '' } .` ,
49- 'Missing objects:' , {
50- GMBridge : typeof window . GMBridge ,
51- ResourceManager : typeof window . GMBridge ?. ResourceManager ,
52- GMAPIRegistry : typeof window . GMBridge ?. GMAPIRegistry ,
53- ExternalScriptLoader : typeof window . GMBridge ?. ExternalScriptLoader ,
54- executeUserScriptWithDependencies : typeof window . GMBridge ?. executeUserScriptWithDependencies
55- }
56- ) ;
57- }
24+ if ( window . GMBridge ) {
25+ callback ( ) ;
26+ return ;
5827 }
5928
60- check ( ) ;
29+ window . addEventListener ( 'GMBridgeReady' , ( ) => {
30+ callback ( ) ;
31+ } , { once : true } ) ;
6132 }
6233
6334 function exposeGMInfo ( info ) {
@@ -140,42 +111,15 @@ function createIsolatedWorldExecutor(
140111 requiredUrls ,
141112 gmInfo
142113) {
143- const MAX_RETRIES = 30 ;
144- const RETRY_INTERVAL = 100 ;
145-
146114 function waitForGMBridge ( worldType , callback ) {
147- let retries = 0 ;
148-
149- function check ( ) {
150- const hasRequiredObjects =
151- window . GMBridge ?. ResourceManager &&
152- window . GMBridge ?. GMAPIRegistry &&
153- window . GMBridge ?. ExternalScriptLoader &&
154- window . GMBridge ?. executeUserScriptWithDependencies ;
155-
156- if ( hasRequiredObjects ) {
157- callback ( ) ;
158- return ;
159- }
160-
161- if ( retries < MAX_RETRIES ) {
162- retries ++ ;
163- setTimeout ( check , RETRY_INTERVAL ) ;
164- } else {
165- console . error (
166- `CodeTweak: Timed out waiting for core script to load for script '${ scriptId } '${ worldType ? ` in ${ worldType } world` : '' } .` ,
167- 'Missing objects:' , {
168- GMBridge : typeof window . GMBridge ,
169- ResourceManager : typeof window . GMBridge ?. ResourceManager ,
170- GMAPIRegistry : typeof window . GMBridge ?. GMAPIRegistry ,
171- ExternalScriptLoader : typeof window . GMBridge ?. ExternalScriptLoader ,
172- executeUserScriptWithDependencies : typeof window . GMBridge ?. executeUserScriptWithDependencies
173- }
174- ) ;
175- }
115+ if ( window . GMBridge ) {
116+ callback ( ) ;
117+ return ;
176118 }
177119
178- check ( ) ;
120+ window . addEventListener ( 'GMBridgeReady' , ( ) => {
121+ callback ( ) ;
122+ } , { once : true } ) ;
179123 }
180124
181125 function exposeGMInfo ( info ) {
0 commit comments