This commit is contained in:
2025-05-23 15:04:28 +03:00
parent 106c851401
commit e44a6a70f2
5 changed files with 454 additions and 153 deletions

View File

@@ -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>