-
Notifications
You must be signed in to change notification settings - Fork 0
/
hdbvm.js
155 lines (138 loc) · 3.78 KB
/
hdbvm.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
class Captcha {
root = "https://hdbvm.attachment-studios.tk/api";
element = null;
id = null;
value = false;
constructor() {
this.construct();
}
construct() {
this.load_element();
this.load().then(() => {this.build()});
}
load_element() {
let captcha_el = null;
if (document.getElementsByTagName("captcha").length) {
captcha_el = document.getElementsByTagName("captcha")[0];
}
this.element = captcha_el;
this.value = false;
}
async load() {
await fetch(`${this.root}/new`).then(req => req.json()).then(data => {
this.id = data["id"];
}).catch(err => {
console.log("Captcha Load Unsuccessful.");
console.log(err);
});
}
build() {
this.build_template_1();
}
build_template_1() {
let content = `
<style>
.captcha-image {
aspect-ratio: 16/6;
}
.captcha-content {
width: 100%;
height: 80%;
padding: 0.25rem;
margin: 0;
}
.captcha-message {
font-size: 14px;
}
.captcha-input {
display: flex;
justify-content: space-between;
}
.captcha-input input {
width: 100%;
margin: 0.25rem;
}
.captcha-buttons {
display: flex;
justify-content: space-between;
}
.captcha-buttons button {
width: 100%;
margin: 0.25rem;
}
@media (max-width: 479px) {
captcha {
width: 100%;
}
}
</style>
<div id="captcha-image" class="captcha-image">
<img id="captcha-img" src="${this.root}/img/id/${this.id}" />
</div>
<div id="captcha-content" class="captcha-content">
<div id="captcha-input-box" class="captcha-input">
<input id="captcha-input" placeholder="captcha by hdbvm" required />
</div>
<div id="captcha-buttons" class="captcha-buttons">
<button type="button" onclick="captcha.submit();">Submit</button>
<button type="button" onclick="captcha.reload();">Reload</button>
</div>
<div id="captcha-message" class="captcha-message"></div>
</div>
`;
this.element.style = `
display: flex;
background: white;
aspect-ratio: 32/7;
width: 50%;
border-radius: 0.25rem;
margin: 0.25rem;
padding: 0;
overflow: hidden;
min-width: 21.5095rem;
`;
this.element.innerHTML = content;
}
async submit() {
document.getElementById("captcha-message").innerHTML = "checking...";
let captcha_value = document.getElementById("captcha-input").value;
if (captcha_value == "") {
this.value = false;
document.getElementById("captcha-input").focus();
document.getElementById("captcha-message").innerHTML = "Captcha Required!";
return;
}
await fetch(`${this.root}/check/${this.id}/${captcha_value}`).then(req => req.json()).then(data => {
if (data["exists"] == true) {
if (data["result"] == true) {
this.value = true;
document.getElementById("captcha-content").innerHTML = "Captcha Correct!";
} else {
this.value = false;
document.getElementById("captcha-input").focus();
document.getElementById("captcha-message").innerHTML = "Captcha Incorrect!";
}
} else {
document.getElementById("captcha-img").src = document.getElementById("captcha-img").src + "?" + new Date().getTime();
document.getElementById("captcha-message").innerHTML = "Captcha Expired!";
}
}).catch(err => {
console.log("Captcha Load Unsuccessful.");
console.log(err);
});
}
async reload() {
document.getElementById("captcha-message").innerHTML = "reloading...";
await fetch(`${this.root}/renew/${this.id}`).then(req => req.json()).then(data => {
if (data["exists"] == false) {
this.construct();
} else {
document.getElementById("captcha-img").src = document.getElementById("captcha-img").src + "?" + new Date().getTime();
}
}).catch(err => {
console.log("Captcha Load Unsuccessful.");
console.log(err);
});
}
}
captcha = new Captcha();