68 lines
2.5 KiB
HTML
68 lines
2.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
<title>JS Reading App</title>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/styles/default.min.css">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-light.min.css">
|
|
|
|
<script src="https://unpkg.com/htmx.org@1.9.9"></script>
|
|
</head>
|
|
<body>
|
|
<nav class="navbar" role="navigation" aria-label="main navigation">
|
|
<div class="navbar-menu is-active">
|
|
<div class="navbar-start">
|
|
<a class="navbar-item" href="#" hx-post="/api/v1/logout">
|
|
<img src="images/js_logo.svg" alt="js logo" style="height: 100%">
|
|
<h2 class="title is-4 ml-1" style="display: inline;">Reading Exercices</h2>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
<div hx-get="/api/v1/random-questions/:seed/:defaultIndex"
|
|
hx-trigger="load"
|
|
id="question-body">
|
|
</div>
|
|
|
|
<script>
|
|
|
|
function getIndexFromHash(){
|
|
if(document.location.hash.length < 2){
|
|
return null;
|
|
}
|
|
const ret = document.location.hash.substr(1)
|
|
if(isNaN(ret)){
|
|
return ret;
|
|
}
|
|
return parseInt(ret) - 1;
|
|
}
|
|
|
|
function getDefaultIndex(){
|
|
return getIndexFromHash() || localStorage.getItem("defaultIndex") || '0';
|
|
}
|
|
|
|
document.body.addEventListener('htmx:configRequest', function(evt) {
|
|
evt.detail.headers.session = localStorage.getItem("seed");
|
|
evt.detail.path = evt.detail.path.replace(":seed", localStorage.getItem("seed"));
|
|
|
|
evt.detail.path = evt.detail.path.replace(":defaultIndex", getDefaultIndex());
|
|
});
|
|
document.body.addEventListener('logout', function (evt) {
|
|
window.localStorage.clear();
|
|
document.location.href = "/login.html";
|
|
});
|
|
|
|
document.body.addEventListener('set-question-id', function (evt) {
|
|
if(isNaN(evt.detail.value)){
|
|
return;
|
|
}
|
|
document.location.hash = parseInt(evt.detail.value) + 1;
|
|
localStorage.setItem("defaultIndex", evt.detail.value);
|
|
});
|
|
|
|
</script>
|
|
</body>
|
|
</html> |