forked from TomGrobbe/vMenu
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstorage.html
More file actions
276 lines (245 loc) · 6.91 KB
/
storage.html
File metadata and controls
276 lines (245 loc) · 6.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vMenu</title>
</head>
<style>
@import url('https://fonts.googleapis.com/css2?family=Roboto&display=swap');
* {
margin: 0;
padding: 0;
text-align: center;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
}
#body {
margin-top: 50px;
max-width: 1200px;
margin-left: auto;
margin-right: auto;
background-color: rgba(255, 255, 255, 0.8);
}
.error {
background-color: lightcoral;
color: rgb(121, 34, 34);
padding: 30px;
}
input[type="checkbox"]:not(:checked)+div {
display: none;
}
hr {
margin-top: 10px;
margin-bottom: 10px;
border: none;
border-top: 1px solid lightgray;
}
button:not(#close-button) {
padding: 5px 10px;
border: none;
border-radius: 3px;
background-color: #0075ff;
font-size: 14px;
color: white;
}
#close-button {
position: relative;
top: 0;
right: 5px;
background: none;
border: none;
float: right;
font-size: 20px;
font-weight: 100;
color: gray;
}
.grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
}
.column {
padding: 20px;
}
.column:first-of-type {
border-right: 1px solid lightgray;
}
textarea {
width: 100%;
height: 100%;
text-align: left;
padding: 5px;
}
strong {
color: rgb(189, 45, 45);
}
.mt {
display: block;
margin-top: 8px;
}
.mb {
display: block;
margin-bottom: 8px;
}
.left {
text-align: left;
}
ol,
li {
text-align: left;
}
ol {
margin-left: 20px;
}
input[type=file] {
margin-top: 8px;
margin-bottom: 8px;
}
</style>
<body>
<div id="body"
hidden>
<button id="close-button">×</button>
<h2 class="mt">IMPORTANT</h2>
<p class="mb"><strong>Use this feature at your own risk, YOU are
responsible for any potential data loss or corruption.</strong>
</p>
<input type="checkbox"> I accept the risk and take full responsibility
for my actions, now let me in!
<div class="mt mb">
<div class="error"
id="error-div"
hidden>
</div>
<div class="grid">
<div class="column">
<form onsubmit="importData()">
<div class="group">
<h3>Import vMenu data</h3>
<p>
<strong>Warning</strong>: This <em>will</em>
replace any existing data.
Make a backup before you do this!
</p>
<textarea id="import-data"
class="mt mb"
placeholder="Paste the JSON data in here."
rows="5"></textarea>
<p class="mt mb">Alternatively, select a JSON file
containing exported data directly.</p>
<strong>Note:</strong>
<p>
This probably won't work when you're in
fullscreen mode.
</p>
<input type="file"
id="import-file"
placeholder="Import a file">
<hr>
<button type="submit">Click to import data</button>
</div>
</form>
</div>
<div class="column">
<form>
<div class="group">
<h3>Export vMenu data</h3>
<strong>Note:</strong>
<p class="mt">Do not edit the contents of this
export if you don't know what you're doing.
Importing edited content may result in data
corruption. Which means that all your saved data
will be deleted when you restart your game.</p>
<strong class="mt">Instructions:</strong>
<ol>
<li>
Select all text using <kbd>CTRL + A</kbd> in
the textarea below, and use <kbd>CTRL +
C</kbd> to copy it.
</li>
<li>
Use <kbd>CTRL + V</kbd> to paste the data in
something like notepad.
</li>
<li>
Save the file somewhere as a
<kbd>.json</kbd> file.
</li>
</ol>
<textarea rows="5"
disabled
class="mt left"
placeholder="Exported data will appear here automatically, if you see this text, something went wrong :("
id="output"></textarea>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
document.getElementById("close-button").onclick = () => {
event.preventDefault();
document.getElementById("body").setAttribute("hidden", "");
fetch(`https://${GetParentResourceName()}/disableImportExportNUI`, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=UTF-8',
},
body: JSON.stringify({ close: true })
});
}
var jsonData = "{}";
var error_div = document.getElementById("error-div");
var importTextField = document.getElementById("import-data");
function importData() {
event.preventDefault();
error_div.setAttribute("hidden", "");
let el = document.getElementById("import-file");
if (el != null && el.files.length == 1) {
let file = el.files[0];
if (file != null && file.type === "application/json") {
let reader = new FileReader();
reader.onload = (a) => {
jsonData = a.target.result;
postImportData();
};
reader.readAsText(file);
} else {
if ((importTextField.value || "").trim() != "") {
jsonData = importTextField.value;
postImportData();
return;
} else {
error_div.removeAttribute("hidden");
error_div.innerText = "No valid JSON file is selected and the textarea is empty!";
}
}
} else {
if ((importTextField.value || "").trim() != "") {
jsonData = importTextField.value;
postImportData();
return;
} else {
error_div.removeAttribute("hidden");
error_div.innerText = "You did not select a file and the textarea is empty!";
}
}
}
function postImportData() {
fetch(`https://vMenu/importData`, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonData
}).then(resp => resp.json()).then(resp => {
document.getElementById("body").setAttribute("hidden", "");
});
}
window.addEventListener("message", (data) => {
document.getElementById("body").removeAttribute("hidden");
document.getElementById("output").innerText = JSON.stringify(data.data);
})
</script>
</body>
</html>