@@ -33,9 +33,7 @@ type State = {
3333} ;
3434
3535const state : State = {
36- textarea : CustomText . getText ( ) . join (
37- CustomText . getPipeDelimiter ( ) ? "|" : " "
38- ) ,
36+ textarea : "" ,
3937 longCustomTextWarning : false ,
4038 challengeWarning : false ,
4139 customTextMode : "simple" ,
@@ -167,27 +165,29 @@ async function beforeAnimation(
167165 modalEl : HTMLElement ,
168166 modalChainData ?: IncomingData
169167) : Promise < void > {
170- state . customTextMode = CustomText . getMode ( ) ;
168+ const customText = await CustomText . getData ( ) ;
169+ state . textarea = customText . text . join ( customText . pipeDelimiter ? "|" : " " ) ;
170+ state . customTextMode = customText . mode ;
171171
172172 if (
173173 state . customTextMode === "repeat" &&
174- CustomText . getLimitMode ( ) === "word" &&
175- CustomText . getLimitValue ( ) === CustomText . getText ( ) . length
174+ customText . limit . mode === "word" &&
175+ customText . limit . value === customText . text . length
176176 ) {
177177 state . customTextMode = "simple" ;
178178 }
179179
180180 state . customTextLimits . word = "" ;
181181 state . customTextLimits . time = "" ;
182182 state . customTextLimits . section = "" ;
183- if ( CustomText . getLimitMode ( ) === "word" ) {
184- state . customTextLimits . word = `${ CustomText . getLimitValue ( ) } ` ;
185- } else if ( CustomText . getLimitMode ( ) === "time" ) {
186- state . customTextLimits . time = `${ CustomText . getLimitValue ( ) } ` ;
187- } else if ( CustomText . getLimitMode ( ) === "section" ) {
188- state . customTextLimits . section = `${ CustomText . getLimitValue ( ) } ` ;
183+ if ( customText . limit . mode === "word" ) {
184+ state . customTextLimits . word = `${ customText . limit . value } ` ;
185+ } else if ( customText . limit . mode === "time" ) {
186+ state . customTextLimits . time = `${ customText . limit . value } ` ;
187+ } else if ( customText . limit . mode === "section" ) {
188+ state . customTextLimits . section = `${ customText . limit . value } ` ;
189189 }
190- state . customTextPipeDelimiter = CustomText . getPipeDelimiter ( ) ;
190+ state . customTextPipeDelimiter = customText . pipeDelimiter ;
191191
192192 state . longCustomTextWarning = CustomTextState . isCustomTextLong ( ) ?? false ;
193193
@@ -220,9 +220,10 @@ async function afterAnimation(): Promise<void> {
220220 }
221221}
222222
223- export function show ( showOptions ?: ShowOptions ) : void {
224- state . textarea = CustomText . getText ( )
225- . join ( CustomText . getPipeDelimiter ( ) ? "|" : " " )
223+ export async function show ( showOptions ?: ShowOptions ) : Promise < void > {
224+ const customText = await CustomText . getData ( ) ;
225+ state . textarea = customText . text
226+ . join ( customText . pipeDelimiter ? "|" : " " )
226227 . replace ( / ^ + / gm, "" ) ;
227228 void modal . show ( {
228229 ...( showOptions as ShowOptions < IncomingData > ) ,
@@ -310,7 +311,7 @@ function cleanUpText(): string[] {
310311 return words ;
311312}
312313
313- function apply ( ) : void {
314+ async function apply ( ) : Promise < void > {
314315 if ( state . textarea === "" ) {
315316 Notifications . add ( "Text cannot be empty" , 0 ) ;
316317 return ;
@@ -363,29 +364,29 @@ function apply(): void {
363364 }
364365
365366 if ( state . customTextMode === "simple" ) {
366- CustomText . setMode ( "repeat" ) ;
367+ await CustomText . setMode ( "repeat" ) ;
367368 state . customTextLimits . word = `${ text . length } ` ;
368369 state . customTextLimits . time = "" ;
369370 state . customTextLimits . section = "" ;
370371 } else {
371- CustomText . setMode ( state . customTextMode ) ;
372+ await CustomText . setMode ( state . customTextMode ) ;
372373 }
373374
374- CustomText . setPipeDelimiter ( state . customTextPipeDelimiter ) ;
375- CustomText . setText ( text ) ;
375+ await CustomText . setPipeDelimiter ( state . customTextPipeDelimiter ) ;
376+ await CustomText . setText ( text ) ;
376377
377378 if ( state . customTextMode === "simple" && state . customTextPipeDelimiter ) {
378- CustomText . setLimitMode ( "section" ) ;
379- CustomText . setLimitValue ( text . length ) ;
379+ await CustomText . setLimitMode ( "section" ) ;
380+ await CustomText . setLimitValue ( text . length ) ;
380381 } else if ( state . customTextLimits . word !== "" ) {
381- CustomText . setLimitMode ( "word" ) ;
382- CustomText . setLimitValue ( parseInt ( state . customTextLimits . word ) ) ;
382+ await CustomText . setLimitMode ( "word" ) ;
383+ await CustomText . setLimitValue ( parseInt ( state . customTextLimits . word ) ) ;
383384 } else if ( state . customTextLimits . time !== "" ) {
384- CustomText . setLimitMode ( "time" ) ;
385- CustomText . setLimitValue ( parseInt ( state . customTextLimits . time ) ) ;
385+ await CustomText . setLimitMode ( "time" ) ;
386+ await CustomText . setLimitValue ( parseInt ( state . customTextLimits . time ) ) ;
386387 } else if ( state . customTextLimits . section !== "" ) {
387- CustomText . setLimitMode ( "section" ) ;
388- CustomText . setLimitValue ( parseInt ( state . customTextLimits . section ) ) ;
388+ await CustomText . setLimitMode ( "section" ) ;
389+ await CustomText . setLimitValue ( parseInt ( state . customTextLimits . section ) ) ;
389390 }
390391
391392 ChallengeController . clearActive ( ) ;
@@ -554,9 +555,11 @@ async function setup(modalEl: HTMLElement): Promise<void> {
554555 } ) ;
555556 }
556557 } ) ;
557- modalEl . querySelector ( ".button.apply" ) ?. addEventListener ( "click" , ( ) => {
558- apply ( ) ;
559- } ) ;
558+ modalEl
559+ . querySelector ( ".button.apply" )
560+ ?. addEventListener ( "click" , async ( ) => {
561+ await apply ( ) ;
562+ } ) ;
560563 modalEl . querySelector ( ".button.wordfilter" ) ?. addEventListener ( "click" , ( ) => {
561564 void WordFilterPopup . show ( {
562565 modalChain : modal as AnimatedModal < unknown , unknown > ,
0 commit comments