new
This commit is contained in:
27
example.html
27
example.html
@@ -24,15 +24,38 @@
|
||||
async function runWasm() {
|
||||
await init();
|
||||
|
||||
document.getElementById('getSecretValue').addEventListener('click', () => {
|
||||
|
||||
document.getElementById('getSecretValue').addEventListener('click', async () => {
|
||||
const userAgent = document.getElementById('userAgent').value || navigator.userAgent; // Используем введенный user agent или стандартный
|
||||
const url = document.getElementById('url').value || window.location.href; // Используем введенный URL или текущий
|
||||
|
||||
const serverTs = await fetchServerTimestamp()
|
||||
const secretValue = await get_secret_value(BigInt(serverTs.timestamp), userAgent, url);
|
||||
// const asd = await fetch_timestamp();
|
||||
|
||||
const secretValue = get_secret_value(BigInt(Math.floor(Date.now() / 1000)), userAgent, url);
|
||||
document.getElementById('result').innerText = secretValue;
|
||||
});
|
||||
}
|
||||
|
||||
async function fetchServerTimestamp() {
|
||||
const url = "https://api.id.hublab.ru/api/v1/server-timestamp";
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
// Проверяем, успешен ли ответ
|
||||
if (!response.ok) {
|
||||
throw new Error(`Ошибка HTTP: ${response.status}`);
|
||||
}
|
||||
// Парсим JSON из ответа
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Произошла ошибка при получении времени сервера:", error);
|
||||
return null; // Возвращаем null в случае ошибки
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
runWasm();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user