-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDokustash_Generator.html
214 lines (186 loc) · 6.06 KB
/
Dokustash_Generator.html
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
<!--Nav Template Start-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=0.5">
<title>DokuStash Generator - SyndiShanX</title>
<link rel="stylesheet" href="Fonts/Font_Awesome.min.css">
<link rel="icon" href="Images/Global/Icon.webp">
<link rel="stylesheet" href="GlobalCSS.css">
<style type="text/css">
textarea {
font-size: 25px;
color: #248d6c;
background-color: #383838;
border: none;
resize:none;
}
input {
background-color: #383838;
border: none;
}
font {
font-family: 'Montserrat', sans-serif;
font-weight: bold;
line-height: 1.15;
}
a.syn {
color: #35AFEA;
}
</style>
</head>
<body lang="" onLoad="getJSON()">
<div class="MainWrapper" align="center">
<!--Nav Template End-->
<font color="#8d2424" size="8">Random Stash Generator</font><br><br>
<font color="#8d5024" size="4">Between</font>
<textarea id="lownumber" rows="1" cols="5" maxlength="5">1</textarea>
<font color="#8d7824" size="4">and</font>
<textarea id="highnumber" rows="1" cols="5" maxlength="5"></textarea><br><br>
<button class="blueButton" id="generateNum" onClick="{ rollNumber(); genStashFileData(); }">Generate New Texture</button><br><br>
<textarea readonly id="randomnumber" rows="1" cols="5" maxlength="5"></textarea><br><br>
<a class="syn" href="" target="_blank" alt="DokuStash" id="DokuLinkElement"></a><br><br>
<font color="#8d7824" size="6"><p id="DokuContributorElement"></p></font><br>
<img id="DokuIMGElement" style="image-rendering: pixelated; image-rendering: -moz-crisp-edges; image-rendering: crisp-edges;" src="Images/Global/Icon_Tab.webp" width="256" height="256"><br><br>
<font color="Purple" size="6"><p id="DokuTagElement"></p></font>
<!--Nav Template Start-->
</div>
<script>
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
</script>
<script>
function getJSON() {
"use strict";
var fileName = "",
stashFiles,
StashID;
StashID = document.getElementById("randomnumber").value;
async function getFileData() {
await fetch('https://gh.dokucraft.co.uk/stash-files/files.json').then(res => res.json()).then(files => {
async function StashFileData() {
await sleep(500);
const fileNames = Object.keys(files)
window.stashFileNames = fileNames;
let maxID = 0
for (let fileName of fileNames) {
files[fileName].id = parseInt(fileName.match(/.+_(\d+)/)[1])
maxID = Math.max(maxID, files[fileName].id)
}
fileNames.sort((a, b) => files[a].id - files[b].id)
window.stashFiles = files;
maxID = Object.values(files).reduce((a,e) => a = Math.max(a, e.id), 0);
document.getElementById("highnumber").innerHTML = maxID;
var stashRandomNumber = files[fileNames[Math.floor(Math.random()*fileNames.length)]].id
var numLowID = document.getElementById("lownumber").value
var numHighID = document.getElementById("highnumber").value
if (stashRandomNumber < numLowID) {
rollNumber()
}
if (stashRandomNumber > numHighID) {
rollNumber()
}
document.getElementById("randomnumber").innerHTML = stashRandomNumber
genStashFileData()
}
StashFileData();
})
}
getFileData();
}
</script>
<script>
function genStashFileData() {
"use strict";
var DokuIMGWidth = "",
DokuIMGHeight,
DokuIMGRatio,
DokuLink,
DokuIMGLink,
FileSize,
FileTags,
FileTags1,
StashFile0,
StashFile1,
StashID,
Contributor,
ContributorName,
StashFile,
StashIMGLink,
StashExtension1,
StashExtension2;
StashID = document.getElementById("randomnumber").value;
const nameOf = id => {
const bs = (s, e) => {
if (e < s) return null // No result
const c = Math.floor((s + e) * .5)
if (stashFiles[stashFileNames[c]].id == id) {
return stashFileNames[c] // File found
}
if (stashFiles[stashFileNames[c]].id < id) {
return bs(c + 1, e) // File is in upper half
} else {
return bs(s, c - 1) // File is in lower half
}
}
return bs(0, stashFileNames.length - 1)
}
console.log(nameOf(StashID))
StashFile = nameOf(StashID)
StashExtension1 = StashFile.split(".zip")
StashFile1 = nameOf(StashID)
if (StashExtension1.length == "1") {
StashIMGLink = "https://gh.dokucraft.co.uk/stash-files/files/";
} else if (StashExtension1.length == "2") {
StashIMGLink = "https://gh.dokucraft.co.uk/stash-files/thumbnails/";
StashExtension1 = StashFile.split(".zip");
StashExtension2 = StashExtension1[0] + ".png";
StashFile1 = StashExtension2;
}
ContributorName = StashFile1.split("_" + StashID)
Contributor = ContributorName[0]
FileSize = (stashFiles[StashFile].S)
FileTags = (stashFiles[StashFile].T)
DokuIMGWidth = FileSize[0]
DokuIMGHeight = FileSize[1]
DokuIMGRatio = DokuIMGHeight / DokuIMGWidth
document.getElementById("DokuContributorElement").innerText = "Contributor: " + Contributor;
DokuLink = "https://stash.dokucraft.co.uk/?details=" + StashID;
document.getElementById("DokuLinkElement").innerHTML = DokuLink;
document.getElementById("DokuLinkElement").href = DokuLink;
DokuIMGLink = StashIMGLink + StashFile1;
document.getElementById("DokuIMGElement").src = DokuIMGLink;
document.getElementById("DokuIMGElement").width = 256;
document.getElementById("DokuIMGElement").height = DokuIMGRatio * 256;
if (FileTags == undefined) {
} else {
FileTags1 = FileTags.split(",")
document.getElementById("DokuTagElement").innerText = "Tags: " + FileTags1.join(', ');
}
}
</script>
<script>
function rollNumber() {
stashRandomNumber = stashFiles[stashFileNames[Math.floor(Math.random()*stashFileNames.length)]].id
numLowID = document.getElementById("lownumber").value
numHighID = document.getElementById("highnumber").value
var numLowID = document.getElementById("lownumber").value
var numHighID = document.getElementById("highnumber").value
if (stashRandomNumber < numLowID) {
rollNumber()
}
if (stashRandomNumber > numHighID) {
rollNumber()
}
document.getElementById("randomnumber").innerHTML = stashRandomNumber
}
</script>
<script src="GlobalNavbar.js"></script>
<script src="GlobalNavbarFixer.js"></script>
</body>
</html>
<!--Nav Template End-->