@@ -189,23 +189,22 @@ <h1>Wispcraft Injector</h1>
189189 const htmlFile = fileElem . files [ 0 ] ;
190190 const reader = new FileReader ( ) ;
191191 reader . onload = function ( e ) {
192- let content = e . target . result ;
193- let index = content . toLowerCase ( ) . indexOf ( "<head>" ) ;
194- if ( index == - 1 ) {
192+ const content = e . target . result ;
193+ const parser = new DOMParser ( ) ;
194+ const doc = parser . parseFromString ( content , "text/html" ) ;
195+ if ( ! doc . head ) {
195196 alert ( "Invalid client file!" ) ;
196197 fileElem . value = "" ;
197198 fileElem . removeAttribute ( "disabled" ) ;
198199 return ;
199200 }
200- index += 6 ;
201-
202- let inject = `
203- <script type="text/javascript">
204- ${ atob ( getWispcraftBundle ( ) ) }
205- <${ "/" } script>
206- ` ;
207- content = content . slice ( 0 , index ) + inject + content . slice ( index ) ;
208- const blob = new Blob ( [ content ] , {
201+ const script = doc . createElement ( "script" ) ;
202+ script . type = "text/javascript" ;
203+ script . textContent = atob ( getWispcraftBundle ( ) ) ;
204+ doc . head . appendChild ( script ) ;
205+ const serializer = new XMLSerializer ( ) ;
206+ const finalContent = serializer . serializeToString ( doc ) ;
207+ const blob = new Blob ( [ finalContent ] , {
209208 type : "text/html; charset=utf-8" ,
210209 } ) ;
211210 downloadLink . download = "wispcraft-" + htmlFile . name ;
0 commit comments