forked from hackthedev/dcts-shipping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt.js
221 lines (184 loc) · 7.01 KB
/
prompt.js
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
var promptBox;
var promptIcon;
var promptTitle;
var promptText;
var promptInputText;
var promptInputNumber;
var promptInputs;
var promptInputYes;
var promptInputNo;
var promptInputCancel;
var promptInputOk;
function closePrompt(){
//promptBox.style.display = "none";
promptBox.style.animation = "fadeout 0.5s";
setTimeout(() => {
promptBox.style.display = "none";
}, "300");
setTimeout(() => {
promptInputs.style.display = "none";
promptInputYes.style.display = "none";
promptInputNo.style.display = "none";
promptInputCancel.style.display = "none";
promptInputOk.style.display = "none";
promptInputText.style.display = "none";
promptInputNumber.style.display = "none";
}, "500");
}
function getElements(){
promptBox = document.getElementById("prompt-container");
promptIcon = document.getElementById("prompt-icon");
promptTitle = document.getElementById("prompt-title");
promptText = document.getElementById("prompt-text");
promptInputText = document.getElementById("prompt-input-text");
promptInputNumber = document.getElementById("prompt-input-number");
promptInputs = document.getElementById("prompt-input-container");
promptInputYes = document.getElementById("prompt-button-yes");
promptInputNo = document.getElementById("prompt-button-no");
promptInputCancel = document.getElementById("prompt-button-cancel");
promptInputOk = document.getElementById("prompt-button-ok");
}
function setupPrompt(){
var code =
`
<div id="prompt-container" style="display: none;">
<div id="prompt-content-container">
<div id="prompt-img-container">
<img id="prompt-icon" onerror="this.src='/img/error.png';"
src="">
</div>
<div id="prompt-text-container">
<h1 id="prompt-title">Oh yikes!</h1><br>
<p id="prompt-text" style="margin-top: 0;padding-top: 0;">
You've found a easter egg :0
</p><br>
<div id="prompt-input-container" style="display: none;">
<input id="prompt-input-text" style="display: none;" type="text"/>
<input id="prompt-input-number" style="display: none;" type="number"/>
<button id="prompt-button-ok" style="display: none;">Ok</button>
<button id="prompt-button-cancel" style="display: none;">Cancel</button>
<button id="prompt-button-yes" style="display: none;">Yes</button>
<button id="prompt-button-no" style="display: none;">No</button>
</div>
</div>
</div>
</div>
`;
document.body.insertAdjacentHTML("beforeend", code);
getElements();
}
var promptPromise;
async function Confirm(title, text, icon, button, type) {
getElements();
promptBox.style.display = "block";
promptBox.style.animation = "fadein 0.5s";
promptTitle.innerHTML = title.replaceAll("#", "<br>");;
promptText.innerHTML = text.replaceAll("#", "<br>");
promptButtonClick = null;
var withText = false;
var withNumber = false;
var confirming = false;
if(type == null){
console.log("Couldnt show confirmation box because the type was null");
}
promptIcon.src = "/img/" + icon + ".png";
promptIcon.onerror = () => {
promptIcon.src = "/img/error.png";
}
if (Array.isArray(type) == true) {
type.forEach(input => {
if (input == "text") {
promptInputText.style.display = "block";
withNumber = true;
}
if (input == "number") {
withNumber = true;
promptInputNumber.style.display = "block";
}
if (input == "confirm") {
confirming = true;
}
});
} else {
if (type == "text") {
withText = true;
promptInputText.style.display = "block";
} else if (type == "number") {
withNumber = true;
promptInputNumber.style.display = "block";
}
else if (type == "confirm") {
confirming = true;
}
}
var executionCode = "";
if (Array.isArray(button) == true) {
var firstRun = true;
button.forEach(key => {
if(key[1] == null || key[1].length == 0){
key[1] = "closePrompt();";
}
if (key[0] == "yes") {
promptInputs.style.display = "block";
promptInputYes.style.display = "block";
promptInputYes.onclick = function(){ promptPromise("yes"); eval(key[1]) };
}
else if (key[0] == "no") {
promptInputs.style.display = "block";
promptInputNo.style.display = "block";
promptInputNo.onclick = function(){ promptPromise("no"); eval(key[1]) };
}
else if (key[0] == "cancel") {
promptInputs.style.display = "block";
promptInputCancel.style.display = "block";
promptInputCancel.onclick = function(){ promptPromise("cancel"); eval(key[1]) };
}
else if (key[0] == "ok") {
promptInputs.style.display = "block";
promptInputOk.style.display = "block";
promptInputOk.onclick = function(){ promptPromise("ok"); eval(key[1]) };
}
else {
if(firstRun == true){
promptInputs.innerHTML = "";
firstRun = false;
}
var token = "B" + generateId(8);
promptInputs.innerHTML += `<button id="${token}">${key[0]}</button>`;
promptInputs.style.display = "block";
document.getElementById(token).onclick = function(){ promptPromise("ok"); eval(key[1]) };
/*
promptInputs.style.display = "block";
promptInputOk.style.display = "block";
promptInputOk.innerText = key[0];
promptInputOk.onclick = function(){ promptPromise("ok"); eval(key[1]) };
*/
}
console.log(key);
});
}
else{
console.log("Button has to be 2 dimentional array")
return;
}
// Magic
// Waits for button press or until promptPromise() is called with value.
var promise = new Promise((resolve) => { promptPromise = resolve });
await promise.then((result) => { btnRes = result });
console.log("Button Result was " + btnRes)
closePrompt();
if(confirming == true){
if(btnRes == "yes"){
return true;
}
else if(btnRes == "no"){
return false;
}
else if(btnRes == "ok"){
return true;
}
else if(btnRes == "cancel"){
return null
}
}
}