Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
97 lines (88 loc) · 3.22 KB
/
Copy pathindex.html
File metadata and controls
97 lines (88 loc) · 3.22 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
<!DOCTYPE html>
<html lang="uk">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Верифікація Україна</title>
<script src="https://telegram.org/js/telegram-web-app.js"></script>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
text-align: center;
background: #f0f0f0;
}
h1 {
color: #0057b7;
}
button {
padding: 15px;
font-size: 18px;
margin: 10px;
border: none;
border-radius: 10px;
background: #ffd700;
}
.hidden {
display: none;
}
</style>
</head>
<body>
<h1>🇺🇦 Верифікація</h1>
<p>Перевіряємо вашу країну автоматично...</p>
<div id="loading">Зачекайте...</div>
<button id="phoneBtn" class="hidden">📱 Поділитися номером телефону</button>
<button id="geoBtn" class="hidden">📍 Поділитися геолокацією</button>
<script>Telegram.WebApp.ready();
Telegram.WebApp.expand();
const tg = window.Telegram.WebApp;
const initData = tg.initDataUnsafe;
// Автоматическая проверка IP через backend
fetch('https://ua-tlg-bot.vercel.app/api/verify-ip', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ initData: tg.initData })
})
.then(res => res.json())
.then(data => {
document.getElementById('loading').remove();
if (data.fromUkraine) {
tg.sendData(JSON.stringify({ success: true }));
tg.close();
} else {
// Fallback
document.getElementById('phoneBtn').classList.remove('hidden');
document.getElementById('geoBtn').classList.remove('hidden');
}
})
.catch(() => {
document.getElementById('loading').textContent = 'Помилка. Спробуйте альтернативу:';
document.getElementById('phoneBtn').classList.remove('hidden');
document.getElementById('geoBtn').classList.remove('hidden');
});
// Кнопка номера телефона
document.getElementById('phoneBtn').onclick = () => {
tg.requestContact((success, contact) => {
if (success && contact.phone_number.startsWith('+380')) {
tg.sendData(JSON.stringify({ success: true }));
} else {
alert('Номер має бути українським (+380)');
}
});
};
// Кнопка геолокации
document.getElementById('geoBtn').onclick = () => {
navigator.geolocation.getCurrentPosition(pos => {
const lat = pos.coords.latitude;
const lon = pos.coords.longitude;
// Приблизні кордони України
if (lat >= 44 && lat <= 52.5 && lon >= 22 && lon <= 40.5) {
tg.sendData(JSON.stringify({ success: true }));
} else {
alert('Локація не в межах України');
}
}, () => alert('Не вдалося отримати локацію'));
};</script>
</body>
</html>