1
- // Cookie/"load" code modified from https://github.com/DEVTomatoCake/dashboard/blob/700b21999a671f4e9c32ba4a1a35f94156db11d4/assets/js/script.js#L16-L31
2
-
3
- function setCookie ( name = "" , value = "" , days = void 0 ) {
4
- let cookie = name + "=" + value + ";path=/;Secure;"
5
- if ( days ) cookie += "expires=" + new Date ( Date . now ( ) + 1000 * 60 * 60 * 24 * days ) . toUTCString ( ) + ";"
6
-
7
- document . cookie = cookie
8
- }
9
- function getCookie ( name ) {
10
- for ( const rawCookie of document . cookie . split ( ";" ) ) {
11
- const cookie = rawCookie . trim ( )
12
- if ( cookie . split ( "=" ) [ 0 ] == name ) return cookie . substring ( name . length + 1 , cookie . length )
13
- }
14
- return void 0
15
- }
1
+ // "load" code modified from https://github.com/DEVTomatoCake/dashboard/blob/700b21999a671f4e9c32ba4a1a35f94156db11d4/assets/js/script.js#L16-L31
16
2
17
3
const requestVersions = async ( ) => {
18
- const res = await fetch ( "https://raw.githubusercontent.com/misode/mcmeta/summary/versions/data.json" )
4
+ const res = await fetch ( "https://raw.githubusercontent.com/misode/mcmeta/summary/versions/data.json" , {
5
+ headers : {
6
+ Accept : "application/json" ,
7
+ "User-Agent" : "DEVTomatoCake/Pack-Analyzer"
8
+ }
9
+ } )
19
10
const json = await res . json ( )
20
11
window . versions = json . map ( ver => ( {
21
12
name : ver . id ,
@@ -91,11 +82,11 @@ let rpExclusive = {
91
82
textures : 0
92
83
}
93
84
94
- window . addEventListener ( "load " , ( ) => {
95
- if ( getCookie ( "theme" ) == "light" ) document . body . classList . add ( "light" )
85
+ window . addEventListener ( "DOMContentLoaded " , ( ) => {
86
+ if ( localStorage . getItem ( "theme" ) == "light" ) document . body . classList . add ( "light" )
96
87
else if ( window . matchMedia ( "(prefers-color-scheme: light)" ) . matches ) {
97
88
document . body . classList . add ( "light" )
98
- setCookie ( "theme" , "light" , 365 )
89
+ localStorage . setItem ( "theme" , "light" )
99
90
}
100
91
101
92
const params = new URLSearchParams ( location . search )
@@ -122,6 +113,46 @@ window.addEventListener("load", () => {
122
113
mainScan ( true )
123
114
}
124
115
116
+ document . getElementById ( "clear-results" ) . addEventListener ( "click" , ( ) => {
117
+ document . getElementById ( "progress" ) . innerText = ""
118
+ document . getElementById ( "result" ) . innerHTML = ""
119
+ document . getElementById ( "resultButtons" ) . hidden = true
120
+ document . getElementById ( "shareImage" ) . style . display = "none"
121
+ if ( interval ) clearInterval ( interval )
122
+ } )
123
+ document . getElementById ( "toggle-theme" ) . addEventListener ( "click" , ( ) => {
124
+ localStorage . setItem ( "theme" , document . body . classList . toggle ( "light" ) ? "light" : "dark" )
125
+ } )
126
+ document . getElementById ( "about-button" ) . addEventListener ( "click" , ( ) => openDialog ( document . getElementById ( "aboutDialog" ) ) )
127
+
128
+ document . getElementById ( "select-folder" ) . addEventListener ( "click" , ( ) => {
129
+ if ( interval ) clearInterval ( interval )
130
+ selected = null
131
+
132
+ const input = document . createElement ( "input" )
133
+ input . type = "file"
134
+ input . webkitdirectory = true
135
+ input . onchange = e => {
136
+ selected = e . target . files
137
+ mainScan ( )
138
+ }
139
+ if ( "showPicker" in HTMLInputElement . prototype ) input . showPicker ( )
140
+ else input . click ( )
141
+ } )
142
+ document . getElementById ( "select-zip" ) . addEventListener ( "click" , ( ) => {
143
+ if ( interval ) clearInterval ( interval )
144
+
145
+ const input = document . createElement ( "input" )
146
+ input . type = "file"
147
+ input . accept = ".zip"
148
+ input . onchange = e => handleZip ( e . target . files [ 0 ] )
149
+
150
+ if ( "showPicker" in HTMLInputElement . prototype ) input . showPicker ( )
151
+ else input . click ( )
152
+ } )
153
+
154
+ for ( const elem of document . getElementsByClassName ( "share" ) ) elem . addEventListener ( "click" , ( ) => share ( elem . dataset . type ) )
155
+
125
156
if ( location . protocol == "https:" && "serviceWorker" in navigator ) navigator . serviceWorker . register ( "/serviceworker.js" )
126
157
} )
127
158
@@ -182,18 +213,6 @@ function openDialog(dialog) {
182
213
}
183
214
}
184
215
185
- const toggleTheme = ( ) => {
186
- setCookie ( "theme" , document . body . classList . toggle ( "light" ) ? "light" : "dark" , 365 )
187
- }
188
-
189
- const clearResults = ( ) => {
190
- document . getElementById ( "progress" ) . innerText = ""
191
- document . getElementById ( "result" ) . innerHTML = ""
192
- document . getElementById ( "resultButtons" ) . hidden = true
193
- document . getElementById ( "shareImage" ) . style . display = "none"
194
- if ( interval ) clearInterval ( interval )
195
- }
196
-
197
216
async function share ( type ) {
198
217
let content = ""
199
218
if ( type == "txt" ) content = document . getElementById ( "result" ) . innerText
@@ -239,7 +258,7 @@ async function share(type) {
239
258
if ( res . ok ) {
240
259
document . getElementById ( "share-link" ) . href = "https://sh0rt.zip/" + name
241
260
document . getElementById ( "share-link" ) . innerText = "https://sh0rt.zip/" + name
242
- document . getElementById ( "share-img" ) . src = "https://api.qrserver.com/v1/create-qr-code/?data= " + encodeURIComponent ( "https://sh0rt.zip/" + name ) + "&size=150x150&qzone=2"
261
+ document . getElementById ( "share-img" ) . src = "https://sh0rt.zip/qr/ " + name
243
262
openDialog ( document . getElementById ( "shareDialog" ) )
244
263
} else alert ( "Couldn't create link: " + json . error )
245
264
return
@@ -713,33 +732,6 @@ async function mainScan(hasData = false) {
713
732
} , 100 )
714
733
}
715
734
716
- async function selectFolder ( ) {
717
- if ( interval ) clearInterval ( interval )
718
- selected = null
719
-
720
- const input = document . createElement ( "input" )
721
- input . type = "file"
722
- input . webkitdirectory = true
723
- input . onchange = e => {
724
- selected = e . target . files
725
- mainScan ( )
726
- }
727
- if ( "showPicker" in HTMLInputElement . prototype ) input . showPicker ( )
728
- else input . click ( )
729
- }
730
-
731
- async function selectZip ( ) {
732
- if ( interval ) clearInterval ( interval )
733
-
734
- const input = document . createElement ( "input" )
735
- input . type = "file"
736
- input . accept = ".zip"
737
- input . onchange = e => handleZip ( e . target . files [ 0 ] )
738
-
739
- if ( "showPicker" in HTMLInputElement . prototype ) input . showPicker ( )
740
- else input . click ( )
741
- }
742
-
743
735
function handleZip ( file ) {
744
736
selected = [ ]
745
737
0 commit comments