@@ -32,6 +32,99 @@ socket.onclose = function (e) {
3232 // reconnect
3333 socket = new WebSocket ( "ws://" + window . location . hostname + ":" + ( parseInt ( window . location . port ) + 1 ) + "/" ) ;
3434}
35+ setTimeout ( ( ) => {
36+ UpdateDowngrades ( )
37+ } , 2500 )
38+
39+ function DownloadDowngrade ( package , sourceSha , targetSha , targetVersion ) {
40+ fetch ( "/api/downloaddiff" , {
41+ method : "POST" , body : JSON . stringify ( {
42+ packageName : package ,
43+ sourceSha : sourceSha ,
44+ targetSha : targetSha ,
45+ targetVersion : targetVersion
46+ } )
47+ } )
48+ OpenTab ( "download" )
49+ }
50+ function UpdateDowngrades ( ) {
51+ document . getElementById ( "compatibleDowngrades" ) . innerHTML = `Loading downgrades${ squareLoader } `
52+ fetch ( `https://raw.githubusercontent.com/ComputerElite/APKDowngrader/main/versions.json` ) . then ( res => res . json ( ) . then ( res => {
53+
54+ document . getElementById ( "compatibleDowngrades" ) . innerHTML = `Checking compatibility. This may take 2 minutes${ squareLoader } `
55+ fetch ( `/api/currentsha256` ) . then ( s => s . json ( ) . then ( s => {
56+ var sha = s . msg
57+ var compatible = [ ]
58+ var available = [ ]
59+ for ( const version of res . versions ) {
60+ if ( version . appid == config . currentApp ) {
61+ if ( version . SSHA256 == sha ) {
62+ compatible . push ( version )
63+ } else {
64+ available . push ( version )
65+ }
66+ }
67+ }
68+ var html = ""
69+ if ( compatible . length > 0 ) {
70+ html = `<tr>
71+ <th>Version</th>
72+ <th></th>
73+ <th>Info</th>
74+ </tr>`
75+ for ( const version of compatible ) {
76+ html += `
77+ <tr>
78+ <td>${ version . TV } </td>
79+ <td><div onclick="DownloadDowngrade('${ config . currentApp } ', '${ version . SSHA256 } ', '${ version . TSHA256 } ', '${ version . TV } ')" class="button">Download</div></td>
80+ <td>${ version . Annotation ? version . Annotation : "None" } </td>
81+ </tr>`
82+ }
83+ } else {
84+ html = "No compatible versions found for currently installed version. Please refer to below"
85+ }
86+ document . getElementById ( "compatibleDowngrades" ) . innerHTML = html
87+
88+ if ( available . length > 0 ) {
89+ html = `<tr>
90+ <th>Needed Version</th>
91+ <th>Target Version</th>
92+ <th>Info</th>
93+ </tr>`
94+ for ( const version of available ) {
95+ html += `
96+ <tr>
97+ <td>${ version . SV } </td>
98+ <td>${ version . TV } </td>
99+ <td>${ version . Annotation ? version . Annotation : "None" } </td>
100+ </tr>`
101+ }
102+ } else {
103+ html = "No other downgrades available for this game."
104+ }
105+ document . getElementById ( "availableDowngrades" ) . innerHTML = html
106+
107+ } ) )
108+ } ) ) . catch ( e => {
109+ document . getElementById ( "compatibleDowngrades" ) . innerHTML = `<span style="color: #EE0000;">Error loading downgrades</span>`
110+ } )
111+ fetch ( `/api/patching/getmodstatus` ) . then ( res => res . json ( ) . then ( res => {
112+ document . getElementById ( "currentVersionDowngrade" ) . innerHTML = `Current installed version: ${ res . version } ${ res . isPatched ? "(Patched)" : "" } `
113+ } ) )
114+ }
115+
116+ function FormatBytes ( bytes , decimals = 2 ) {
117+ if ( bytes > 1099511627776 ) return ( input / 1099511627776.0 ) . toFixed ( decimals ) + " TB" ;
118+ // GB
119+ else if ( bytes > 1073741824 ) return ( input / 1073741824.0 ) . toFixed ( decimals ) + " GB" ;
120+ // MB
121+ else if ( bytes > 1048576 ) return ( input / 1048576.0 ) . toFixed ( decimals ) + " MB" ;
122+ // KB
123+ else if ( bytes > 1024 ) return ( input / 1024.0 ) . toFixed ( decimals ) + " KB" ;
124+ // Bytes
125+ else return bytes + " Bytes" ;
126+ }
127+
35128
36129socket . onmessage = function ( e ) {
37130 var data = JSON . parse ( e . data ) ;
0 commit comments