59 lines
1.7 KiB
HTML
59 lines
1.7 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>登入 | TutorOTP</title>
|
|
<style>
|
|
body {
|
|
font-family: sans-serif; padding: 1.5rem; font-size: 1.2rem;
|
|
}
|
|
a, button {
|
|
font-size: 1.1rem;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>TutorOTP</h1>
|
|
<p>已登入為身分 {{USERNAME}}</p>
|
|
<form method="POST" action="/logout">
|
|
<button type="submit">登出</button>
|
|
</form>
|
|
<br>
|
|
<code>{{OTP}}</code>
|
|
<p>
|
|
<button class="setCounter" data-value="{{COUNTER}} - 1">--</button>
|
|
<span>{{COUNTER}}</span>
|
|
<button class="setCounter" data-value="{{COUNTER}} + 1">++</button>
|
|
</p>
|
|
|
|
|
|
<script>
|
|
document.querySelectorAll('.setCounter').forEach(btn => {
|
|
btn.addEventListener('click', async function () {
|
|
const value = eval(this.getAttribute('data-value'));
|
|
try {
|
|
const res = await fetch('/counter', {
|
|
method: 'PUT',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ counter: value })
|
|
});
|
|
|
|
if (!res.ok) {
|
|
alert('伺服器錯誤');
|
|
return;
|
|
}
|
|
|
|
const data = await res.json();
|
|
if (data && data.success) {
|
|
window.location.reload();
|
|
}
|
|
} catch (err) {
|
|
alert('請求失敗: ' + err);
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|