@@ -10,6 +10,8 @@ const urlInput = document.getElementById('urlInput');
1010const loadUrlBtn = document . getElementById ( 'loadUrlBtn' ) ;
1111const discordIdInput = document . getElementById ( 'discordIdInput' ) ;
1212const loadDiscordBtn = document . getElementById ( 'loadDiscordBtn' ) ;
13+ const loadSwgohAsset = document . getElementById ( "loadSwgohAsset" ) ;
14+ const loadSwgohAssetBtn = document . getElementById ( "loadSwgohAssetBtn" ) ;
1315
1416function isTrueWebKit ( ) {
1517 const ua = navigator . userAgent ;
@@ -45,6 +47,92 @@ Object.entries(unwantedEntries).forEach(([key, valuesToRemove]) => {
4547 }
4648} ) ;
4749
50+ let assetVersionPromise ;
51+
52+ async function GetAssetVersionGithub ( ) {
53+ // this function is slightly stolen from swgoh-ae2
54+
55+ if ( ! assetVersionPromise ) {
56+ assetVersionPromise = ( async ( ) => {
57+ const versionGetterUrl = "https://raw.githubusercontent.com/swgoh-utils/gamedata/refs/heads/main/meta.json" ;
58+
59+ const versionResponse = await fetch ( versionGetterUrl ) ;
60+
61+ if ( versionResponse . status === 200 ) {
62+ const metaDataShort = await versionResponse . json ( ) ;
63+ const versionResult = metaDataShort . data . assetVersion ;
64+
65+ console . log ( "Found AssetVersion:" , versionResult ) ;
66+
67+ return versionResult ;
68+ }
69+
70+ console . error ( "Failed to get github version" ) ;
71+ throw new Error ( "Failed to fetch asset version" ) ;
72+ } ) ( ) ;
73+ }
74+
75+ return assetVersionPromise ;
76+ }
77+
78+ const __assetVersion = await GetAssetVersionGithub ( ) ;
79+
80+ const swgohAssetExtractor = "https://legofan-swgoh-ae2.onrender.com" ;
81+
82+ async function wakeAE ( ) {
83+ const assetVersion = await GetAssetVersionGithub ( ) ;
84+ fetch ( `${ swgohAssetExtractor } /Asset/list?version=${ assetVersion } ` ) ;
85+ }
86+
87+ wakeAE ( ) ;
88+ setTimeout ( wakeAE , 300000 ) ;
89+
90+ let loadSwgohAssetLoaded = false ;
91+ loadSwgohAsset . addEventListener ( "focus" , async ( ) => {
92+ if ( loadSwgohAssetLoaded ) {
93+ return ;
94+ }
95+
96+ loadSwgohAsset . innerHTML = "" ;
97+
98+ const loadOption = document . createElement ( "option" ) ;
99+ loadOption . value = "loading..." ;
100+ loadOption . textContent = "loading..." ;
101+ loadSwgohAsset . appendChild ( loadOption ) ;
102+
103+ const assetVersion = await GetAssetVersionGithub ( ) ;
104+
105+ const response = await fetch ( `${ swgohAssetExtractor } /Asset/list?version=${ assetVersion } ` ) ;
106+ const data = await response . json ( )
107+
108+ loadSwgohAsset . innerHTML = "" ;
109+
110+ data . forEach ( item => {
111+ const option = document . createElement ( "option" ) ;
112+ option . value = item ;
113+ option . textContent = item ;
114+ loadSwgohAsset . appendChild ( option ) ;
115+ } ) ;
116+ } ) ;
117+
118+ loadSwgohAssetBtn . addEventListener ( 'click' , async ( ) => {
119+ const selectedAsset = loadSwgohAsset . options [ loadSwgohAsset . selectedIndex ] . text ;
120+
121+ const assetVersion = await GetAssetVersionGithub ( ) ;
122+
123+ const response = await fetch ( `${ swgohAssetExtractor } /Asset/single?version=${ assetVersion } &assetName=${ selectedAsset } ` ) ;
124+ if ( ! response . ok ) {
125+ console . error ( "Failed to fetch asset" )
126+ }
127+
128+ const blob = await response . blob ( )
129+ const reader = new FileReader ( ) ;
130+ reader . onload = function ( event ) {
131+ userImageDataURL = event . target . result ;
132+ } ;
133+ reader . readAsDataURL ( blob ) ;
134+ } ) ;
135+
48136uploadInput . addEventListener ( 'change' , ( e ) => {
49137 const file = e . target . files [ 0 ] ;
50138 if ( ! file ) return ;
@@ -580,6 +668,7 @@ function setupHelpTooltip(btnId, tooltipId) {
580668}
581669setupHelpTooltip ( 'discordHelpBtn' , 'discordHelpTooltip' ) ;
582670setupHelpTooltip ( 'urlHelpBtn' , 'urlHelpTooltip' ) ;
671+ setupHelpTooltip ( 'swgohAssethelpBtn' , 'swgohAssetHelpTooltip' ) ;
583672
584673function showErrorPopup ( message ) {
585674 document . getElementById ( 'popupMessage' ) . textContent = message ;
0 commit comments