-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
225 lines (197 loc) · 7.15 KB
/
Copy pathscript.js
File metadata and controls
225 lines (197 loc) · 7.15 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
// Authored by Kitori
// Made for MadBot Telegram
const tg = window.Telegram.WebApp;
const urlParams = new URLSearchParams(window.location.search);
const groupId = parseInt(urlParams.get("groupid"));
const initData = tg.initData;
const hCaptchaElement = document.getElementById("h-captcha");
const closeButtons = document.getElementsByClassName("close-button");
hCaptchaElement.setAttribute("data-theme", tg.colorScheme || "light");
tg.expand();
const loadingPage = document.getElementById("loading-page");
const captchaPage = document.getElementById("captcha-page");
const molodecPage = document.getElementById("molodec-page");
const tirobotPage = document.getElementById("tirobot-page");
const warningPage = document.getElementById("warning-page");
const acceptButton = document.getElementById('timerButton');
const buttonLoader = document.getElementById('button-loader');
const captchaLoader = document.getElementById('captcha-loader');
let countdownInterval;
function handleGroupInfo(data) {
const pfp = document.getElementById("pfp");
const name = document.getElementById("name");
name.innerText = data.groupTitle;
var imgSource = data.groupAvatarUrl;
console.log(imgSource);
new Promise((resolve, reject) => {
pfp.src = imgSource;
pfp.addEventListener("load", () => {
resolve(pfp);
});
pfp.addEventListener("error", (error) => {
generateLetterImage(data.groupTitle, tg.themeParams.button_color).then((url) => {
pfp.src = url;
});
resolve(pfp);
});
}).then(result => {
loadingPage.classList.remove("visible");
captchaPage.classList.add("visible");
});
}
function handleCaptchaSolve(hCaptchaResponse) {
captchaLoader.classList.add("visible");
const url = "https://tgbot.mxdcxt.top/api/submitcaptcha";
const body = JSON.stringify({
hCaptchaResponse,
initData,
groupId
});
const request = fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body
});
request.then((response) => {
response.text().then((text) => {
const data = JSON.parse(text);
captchaLoader.classList.remove("visible");
captchaPage.classList.remove("visible");
if (data.status === "OK") {
molodecPage.classList.add("visible");
} else if (data.status === "IRL") {
warningPage.classList.add("visible");
initButton(JSON.parse(body));
} else {
tirobotPage.classList.add("visible");
}
});
});
request.catch(() => {
captchaPage.classList.remove("visible");
tirobotPage.classList.add("visible");
});
}
function handleCloseButton() {
tg.close();
}
for (const button of closeButtons) {
button.addEventListener("click", handleCloseButton);
}
function getGroupInfo() {
const url = "https://tgbot.mxdcxt.top/api/getgroupinfo";
const body = JSON.stringify({
initData,
groupId
});
const request = fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body
});
request.then((response) => {
response.text().then((text) => {
if (response.status >= 400) {
loadingPage.classList.remove("visible");
tirobotPage.classList.add("visible");
} else {
const data = JSON.parse(text);
handleGroupInfo(data);
}
});
});
}
function generateLetterImage(title, background) { // da, made by ChatGPT
return new Promise((resolve, reject) => {
const canvas = document.createElement('canvas');
canvas.width = 640;
canvas.height = 640;
const ctx = canvas.getContext('2d');
// Заполняем фон
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Настраиваем шрифт
const letter = title.charAt(0).toUpperCase();
ctx.fillStyle = 'white';
ctx.font = 'normal 320px Arial';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
// Измеряем размеры текста
const metrics = ctx.measureText(letter);
const actualHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;
// Вычисляем позицию для центрирования
const x = canvas.width / 2;
const y = (canvas.height - actualHeight) / 2 + metrics.actualBoundingBoxAscent;
// Рисуем букву
ctx.fillText(letter, x + 8, y + 4);
// Преобразуем canvas в PNG и возвращаем как Data URL
canvas.toBlob((blob) => {
if (blob) {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(blob);
} else {
reject(new Error('Failed to create blob'));
}
}, 'image/png');
});
}
function startCountdown() {
countdownInterval = setInterval(() => {
clearInterval(countdownInterval);
acceptButton.classList.add('active');
acceptButton.disabled = false;
buttonLoader.classList.remove("visible");
acceptButton.classList.remove("invisible");
acceptButton.innerHTML = 'Хорошо';
}, 10000);
}
function initButton(json_body) {
if (countdownInterval) {
clearInterval(countdownInterval);
}
acceptButton.disabled = true;
acceptButton.classList.remove('active');
startCountdown();
acceptButton.onclick = () => {
if (!acceptButton.disabled) {
json_body.irlAccepted = true;
acceptButton.classList.add("invisible");
buttonLoader.classList.add("visible");
const url = "https://tgbot.mxdcxt.top/api/submitcaptcha";
const body = JSON.stringify(json_body);
const request = fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body
});
request.then((response) => {
response.text().then((text) => {
const data = JSON.parse(text);
buttonLoader.classList.remove("visible");
warningPage.classList.remove("visible");
if (data.status === "OK") {
molodecPage.classList.add("visible");
} else if (data.status === "IRL") {
warningPage.classList.add("visible");
initButton(JSON.parse(body));
} else {
tirobotPage.classList.add("visible");
}
});
});
request.catch(() => {
warningPage.classList.remove("visible");
tirobotPage.classList.add("visible");
});
}
};
}
getGroupInfo();