5353 filter : drop-shadow (0 0 10px white);
5454 }
5555
56- h3 {
57- font-size : 24px ;
58- margin : 0 ;
59- }
60-
6156 .button {
6257 background-color : # 0098C5 ;
6358 color : # 000 ;
6459 font-size : 18px ;
6560 border : none;
6661 border-radius : 5px ;
6762 padding : 5px 10px ;
68- margin-top : 10px ;
6963 cursor : pointer;
7064 }
7165
7973 }
8074
8175 .url-list {
82- list-style-type : none;
8376 padding : 0 ;
77+ display : inline-block;
78+ text-align : left;
79+ margin : 0 ;
8480 }
8581
8682 .url-list li {
87- margin-bottom : 5 px ;
83+ margin-bottom : 2 px ;
8884 }
8985
90- .github-link ,
91- .license-link {
86+ a {
9287 color : # 0098C5 ;
9388 text-decoration : none;
9489 }
9590
96- .github-link : hover ,
97- .license-link : hover {
91+ a : hover {
9892 text-decoration : underline;
9993 }
94+
95+ * {
96+ scrollbar-width : auto;
97+ scrollbar-color : # 0097c5 # 000000 ;
98+ }
99+
100+ * ::-webkit-scrollbar {
101+ width : 10px ;
102+ }
103+
104+ * ::-webkit-scrollbar-track {
105+ background : # 000000 ;
106+ }
107+
108+ * ::-webkit-scrollbar-thumb {
109+ background-color : # 0097c5 ;
110+ border-radius : 10px ;
111+ border : 0.5px solid # 006888 ;
112+ }
100113 </ style >
101114 </ head >
102115 < body >
109122 < h1 > EmulatorJS Netplay Server</ h1 >
110123 < img src ="img/logo-light.png " alt ="Logo " class ="logo ">
111124 < p id ="info "> Server info</ p >
112- < h3 > Server Options:</ h3 >
113- < button onclick ="startbutton() " id ="server " class ="button "> Start Server</ button >
125+ < button onclick ="server() " id ="server " class ="button "> Start Server</ button >
114126 < p id ="status "> </ p >
115127 < p id ="nuser "> </ p >
116- < br >
117- < p > URL to use with EmulatorJS:</ p >
118- < ul id ="urls " class ="url-list "> </ ul >
119- < br >
128+ < p > URL's to use with EmulatorJS Netplay: < ul id ="urls " class ="url-list "> </ ul > </ p >
120129 < p > < a href ="https://github.com/EmulatorJS/EmulatorJS-Netplay " target ="_blank " class ="github-link "> View on GitHub</ a > </ p >
121- < p > Licensed under the Apache License 2.0</ p >
122- < p > < a href =" https://github.com/EmulatorJS/EmulatorJS-Netplay/blob/main/LICENSE " target =" _blank " class =" license-link " > Read the whole license here </ a > </ p >
130+ < p > Licensed under the Apache License 2.0 - Read the license < a href =" https://github.com/EmulatorJS/EmulatorJS-Netplay/blob/main/LICENSE " target =" _blank " class =" license-link " > here </ a > </ p >
131+ < br >
123132 </ div >
124133 < script >
134+ const startstop = document . getElementById ( 'server' ) ;
125135 window . addEventListener ( "load" , function ( ) {
126136 const loadingScreen = document . getElementById ( "loading" ) ;
127137 const content = document . getElementById ( "content" ) ;
@@ -135,10 +145,18 @@ <h3>Server Options:</h3>
135145 } ) ;
136146
137147 ( function ( ) {
148+ check ( ) ;
138149 status ( ) . then ( info => {
139150 document . getElementById ( 'info' ) . innerHTML = "Running server on port " + ( info . port || 3000 ) + " with password " + info . password ;
140151 } ) ;
141- document . getElementById ( 'urls' ) . innerHTML = '<li><a href="' + window . location . protocol + "//" + window . location . hostname + ':' + window . location . port + '/" target="_blank" onclick="window.api.openExternal(this.href);event.preventDefault()">' + window . location . protocol + "//" + window . location . hostname + ':' + window . location . port + '/</a></li>' ;
152+ interface ( ) . then ( address => {
153+ address . interfaces . push ( window . location . protocol + "//" + window . location . hostname + ':' + window . location . port + '/' ) ;
154+ address . interfaces = [ ...new Set ( address . interfaces ) ] ;
155+ address . interfaces . forEach ( address => {
156+ document . getElementById ( 'urls' ) . innerHTML += '<li><a href="' + address + '" target="_blank" onclick="window.api.openExternal(this.href);event.preventDefault()">' + address + '</a></li>' ;
157+ } ) ;
158+ } ) ;
159+ checkforusers ( ) ;
142160 } ) ( ) ;
143161
144162 function status ( ) {
@@ -154,35 +172,24 @@ <h3>Server Options:</h3>
154172 } ) ;
155173 }
156174
157- var startstop = document . getElementById ( 'startStop' ) ;
158- function startbutton ( ) {
159- if ( startstop . textContent === 'Start' ) {
160- startstopserver ( "start" ) ;
161- } else if ( startstop . textContent === 'Stop' ) {
162- startstopserver ( "stop" ) ;
163- }
164- update ( ) ;
165- }
166- function update ( ) {
167- if ( startstop . textContent == "Start" ) {
168- document . getElementById ( 'status' ) . style . color = "red" ;
169- document . getElementById ( 'status' ) . innerText = 'NOT RUNNING' ;
170- } else if ( startstop . textContent == "Stop" ) {
171- document . getElementById ( 'status' ) . style . color = "green" ;
172- document . getElementById ( 'status' ) . innerText = 'RUNNING' ;
173- } else {
174- console . error ( "Error!" ) ;
175- }
175+ function interface ( ) {
176+ return fetch ( '/interface' , {
177+ method : 'POST' ,
178+ headers : {
179+ 'Content-Type' : 'application/json'
180+ }
181+ } )
182+ . then ( response => response . json ( ) )
183+ . then ( data => {
184+ return data ;
185+ } ) ;
176186 }
177187 function check ( ) {
178188 fetch ( '/check' , {
179189 method : 'POST' ,
180190 headers : {
181191 'Content-Type' : 'application/json'
182- } ,
183- body : JSON . stringify ( {
184- check : "checking" ,
185- } )
192+ }
186193 } ) . then ( response => response . json ( ) )
187194 . then ( data => {
188195 if ( data == true ) {
@@ -193,6 +200,31 @@ <h3>Server Options:</h3>
193200 update ( ) ;
194201 } ) ;
195202 }
203+ function update ( ) {
204+ if ( startstop . textContent == "Start" ) {
205+ document . getElementById ( 'status' ) . style . color = "red" ;
206+ document . getElementById ( 'status' ) . innerText = 'NOT RUNNING' ;
207+ } else if ( startstop . textContent == "Stop" ) {
208+ document . getElementById ( 'status' ) . style . color = "green" ;
209+ document . getElementById ( 'status' ) . innerText = 'RUNNING' ;
210+ } else {
211+ console . error ( "Error!" ) ;
212+ }
213+ }
214+ function server ( ) {
215+ if ( startstop . textContent === 'Start' ) {
216+ startstopserver ( "start" ) ;
217+ while ( startstop . textContent === 'Start' ) {
218+ check ( ) ;
219+ }
220+ } else if ( startstop . textContent === 'Stop' ) {
221+ startstopserver ( "stop" ) ;
222+ while ( startstop . textContent === 'Stop' ) {
223+ check ( ) ;
224+ }
225+ }
226+ update ( ) ;
227+ }
196228 function startstopserver ( option ) {
197229 fetch ( '/startstop' , {
198230 method : 'POST' ,
@@ -221,7 +253,6 @@ <h3>Server Options:</h3>
221253 }
222254 update ( ) ;
223255 } ) ;
224- location . reload ( ) ;
225256 }
226257 setInterval ( function ( ) {
227258 checkforusers ( ) ;
@@ -232,17 +263,13 @@ <h3>Server Options:</h3>
232263 headers : {
233264 'Content-Type' : 'application/json' ,
234265 'Accept' : 'application/json'
235- } ,
236- body : JSON . stringify ( {
237- "checkn" : true
238- } )
266+ }
239267 } ) . then ( response => response . json ( ) )
240268 . then ( data => {
241269 data = data . users ;
242270 document . getElementById ( 'nuser' ) . innerHTML = "Users connected: " + data ;
243271 } ) ;
244272 }
245- checkforusers ( ) ;
246273 </ script >
247274 </ body >
248275</ html >
0 commit comments