@@ -13,6 +13,25 @@ let i18nStore: Map<string, string>;
1313
1414const i18n = ( key : string ) : string => i18nStore . has ( key ) ? i18nStore . get ( key ) : `#${ key } #` ;
1515
16+ const getLauncherJsonConfig = ( launcherMainContainerEl : HTMLElement ) : JSONObject => {
17+ const scriptTagElement : HTMLScriptElement = launcherMainContainerEl . getElementsByTagName ( 'script' ) [ 0 ] ;
18+ if ( ! scriptTagElement || scriptTagElement . getAttribute ( 'id' ) !== 'launcher-config-json' ) {
19+ throw Error ( 'Could not find launcher config' ) ;
20+ }
21+ return JSON . parse ( scriptTagElement . innerText ) as JSONObject ;
22+ } ;
23+
24+ const initI18NStore = ( config : JSONObject ) : void => {
25+ const phrases : JSONObject = JSON . parse ( config [ 'phrases' ] ) as JSONObject ;
26+
27+ i18nStore = new Map < string , string > ( ) ;
28+ for ( const key in phrases ) {
29+ if ( Object . prototype . hasOwnProperty . call ( phrases , key ) ) {
30+ i18nStore . set ( key , phrases [ key ] ) ;
31+ }
32+ }
33+ } ;
34+
1635class Launcher {
1736 private launcherPanel : HTMLElement ;
1837 private launcherButton : HTMLElement ;
@@ -602,25 +621,6 @@ const getLauncherScriptConfig = (): JSONObject => {
602621 } ;
603622} ;
604623
605- const getLauncherJsonConfig = ( launcherMainContainerEl : HTMLElement ) : JSONObject => {
606- const scriptTagElement : HTMLScriptElement = launcherMainContainerEl . getElementsByTagName ( 'script' ) [ 0 ] ;
607- if ( ! scriptTagElement || scriptTagElement . getAttribute ( 'id' ) !== 'launcher-config-json' ) {
608- throw Error ( 'Could not find launcher config' ) ;
609- }
610- return JSON . parse ( scriptTagElement . innerText ) ;
611- } ;
612-
613- const initI18NStore = ( config : JSONObject ) : void => {
614- const phrases : JSONObject = JSON . parse ( config [ 'phrases' ] ) ;
615-
616- i18nStore = new Map < string , string > ( ) ;
617- for ( let key in phrases ) {
618- if ( phrases . hasOwnProperty ( key ) ) {
619- i18nStore . set ( key , phrases [ key ] ) ;
620- }
621- }
622- } ;
623-
624624const init = ( ) : void => {
625625 const launcherConfig : JSONObject = getLauncherScriptConfig ( ) ;
626626 new Launcher ( launcherConfig ) ;
0 commit comments