6666 color : red;
6767 text-align : center;
6868 }
69+ /* Stile per l'icona di donazione */
70+ .donation-icon {
71+ max-width : 40px ;
72+ vertical-align : middle;
73+ margin-right : 8px ;
74+ }
6975 </ style >
7076 </ head >
7177 < body >
@@ -80,11 +86,10 @@ <h2>Accedi per visualizzare i giochi</h2>
8086 < label for ="password "> Password:</ label >
8187 < input type ="password " id ="password " name ="password " required />
8288 </ div >
89+ <!-- Sezione donazione: verrà popolata dinamicamente tramite version.json -->
8390 < div id ="donation-section ">
84- <!-- Il campo donazione viene visualizzato solo per account che non hanno già attivato l'abbonamento -->
85- < p class ="info "> Per attivare l'abbonamento è richiesta una donazione.</ p >
86- < label for ="donation "> Importo donazione (minimo 5€):</ label >
87- < input type ="number " id ="donation " name ="donation " min ="5 " step ="any " />
91+ <!-- Il contenuto statico viene sostituito dal fetch al file version.json -->
92+ < p class ="info "> Caricamento informazioni donazione...</ p >
8893 </ div >
8994 < button type ="submit "> Accedi</ button >
9095 </ form >
@@ -93,6 +98,7 @@ <h2>Accedi per visualizzare i giochi</h2>
9398
9499 < script >
95100 let accountsData = null ;
101+ let versionData = null ;
96102
97103 // Funzione per caricare i dati degli account da remoto
98104 async function fetchAccounts ( ) {
@@ -108,27 +114,64 @@ <h2>Accedi per visualizzare i giochi</h2>
108114 console . error ( error ) ;
109115 }
110116 }
117+
118+ // Funzione per caricare i dati di versione/donazione
119+ async function fetchVersionInfo ( ) {
120+ try {
121+ const response = await fetch (
122+ "https://raw.githubusercontent.com/Server21/PCGames/refs/heads/main/version.json"
123+ ) ;
124+ if ( ! response . ok ) throw new Error ( "Errore di rete" ) ;
125+ versionData = await response . json ( ) ;
126+ updateDonationSection ( ) ;
127+ } catch ( error ) {
128+ console . error ( "Errore nel caricamento delle info di versione:" , error ) ;
129+ }
130+ }
131+
132+ // Aggiorna il blocco donazione con i dati caricati in version.json
133+ function updateDonationSection ( ) {
134+ const donationSection = document . getElementById ( "donation-section" ) ;
135+ if ( versionData ) {
136+ donationSection . innerHTML = `
137+ <p class="info">
138+ <img src="${ versionData . icon_link } " alt="Icona donazione" class="donation-icon">
139+ ${ versionData . donation_message }
140+ </p>
141+ <label for="donation">Importo donazione (minimo 5€):</label>
142+ <input type="number" id="donation" name="donation" min="5" step="any" />
143+ <p>
144+ <a href="${ versionData . donation_link } " target="_blank">Effettua la donazione</a>
145+ </p>
146+ ` ;
147+ }
148+ }
149+
150+ // Inizializza il fetch dei dati
111151 fetchAccounts ( ) ;
152+ fetchVersionInfo ( ) ;
112153
113- // In base all'username inserito, mostra o nasconde la sezione donazione
154+ // Mostra o nasconde la sezione donazione in base all'account
114155 document . getElementById ( "username" ) . addEventListener ( "blur" , function ( ) {
115156 if ( ! accountsData ) return ;
116157 const username = this . value . trim ( ) ;
117158 const donationSection = document . getElementById ( "donation-section" ) ;
118- // Se l'account esiste e ha proprietà "expires", non è richiesta la donazione
159+ // Se l'account esiste ed è già attivo ( ha proprietà "expires"), nascondiamo la sezione donazione
119160 if ( username in accountsData && typeof accountsData [ username ] === "object" ) {
120161 donationSection . style . display = "none" ;
121162 } else {
122163 donationSection . style . display = "block" ;
123164 }
124165 } ) ;
125166
126- // Gestione del submit con async/await
167+ // Gestione del submit del form con async/await
127168 document . getElementById ( "login-form" ) . addEventListener ( "submit" , async ( e ) => {
128169 e . preventDefault ( ) ;
129170 const username = document . getElementById ( "username" ) . value . trim ( ) ;
130171 const passwordInput = document . getElementById ( "password" ) . value ;
131- const donationValue = document . getElementById ( "donation" ) . value ;
172+ const donationValue = document . getElementById ( "donation" )
173+ ? document . getElementById ( "donation" ) . value
174+ : "" ;
132175 const errorDiv = document . getElementById ( "error-message" ) ;
133176
134177 if ( ! accountsData ) {
0 commit comments