@@ -65,22 +65,53 @@ function initializeMiniApps() {
6565function handleManifestContent ( content ) {
6666 setTimeout ( ( ) => {
6767 const manifest = JSON . parse ( content ) ;
68- let htmlFile = "../miniApps/" + manifest . id + "/" + manifest . htmlFile ;
68+ let miniAppPath = "../miniApps/" + manifest . id + "/" ;
69+
70+ // Load and inject CSS file
71+ if ( manifest . cssFile ) {
72+ const cssFilePath = miniAppPath + manifest . cssFile ;
73+ fetch ( cssFilePath )
74+ . then ( response => response . text ( ) )
75+ . then ( cssContent => {
76+ const styleEl = document . createElement ( 'style' ) ;
77+ styleEl . innerText = cssContent ;
78+ document . head . appendChild ( styleEl ) ;
79+ console . log ( "CSS content added to document head:" , cssFilePath ) ;
80+ } )
81+ . catch ( error => console . error ( "Error loading CSS:" , error ) ) ;
82+ }
6983
84+ // Load and inject HTML file
85+ let htmlFile = miniAppPath + manifest . htmlFile ;
7086 fetch ( htmlFile )
7187 . then ( response => response . text ( ) )
7288 . then ( text => {
7389 ( function ( ) {
7490 var coreDiv = document . getElementById ( 'core' ) ;
7591 if ( coreDiv ) {
76- coreDiv . insertAdjacentHTML ( "beforeend" , text ) ; // ✅ Fix: Keeps existing elements
92+ coreDiv . insertAdjacentHTML ( "beforeend" , text ) ;
7793 console . log ( "HTML content added to core div" ) ;
7894 } else {
7995 console . log ( "Core div not found" ) ;
8096 }
8197 } ) ( ) ;
8298 } )
8399 . catch ( error => console . error ( "Error loading HTML:" , error ) ) ;
100+
101+ // Load and inject JS files from the "scripts" array
102+ const scripts = manifest . scripts || [ ] ;
103+ scripts . forEach ( scriptPath => {
104+ let fullScriptPath = miniAppPath + scriptPath ;
105+ fetch ( fullScriptPath )
106+ . then ( response => response . text ( ) )
107+ . then ( scriptContent => {
108+ const scriptEl = document . createElement ( 'script' ) ;
109+ scriptEl . text = scriptContent ;
110+ document . body . appendChild ( scriptEl ) ;
111+ console . log ( "JS file loaded and executed:" , fullScriptPath ) ;
112+ } )
113+ . catch ( error => console . error ( "Error loading JS:" , error ) ) ;
114+ } ) ;
84115
85116 // Process the manifest data (e.g., create buttons)
86117 const listElement = document . getElementById ( "lst:miniapps" ) ;
0 commit comments