Completely rework justone
This commit is contained in:
+13
-48
@@ -1,48 +1,13 @@
|
||||
<script>
|
||||
const filenames = [
|
||||
'laura.txt',
|
||||
'becker.txt',
|
||||
'junior.txt',
|
||||
'senior.txt',
|
||||
'simon.txt',
|
||||
'lars.txt'
|
||||
];
|
||||
let titles = [];
|
||||
|
||||
function refresh() {
|
||||
document.getElementById('num').innerText = `${titles.length} Begriffe`;
|
||||
}
|
||||
|
||||
async function loadFiles() {
|
||||
filenames.forEach(async filename => {
|
||||
const response = await fetch(filename);
|
||||
if (response.status !== 200) {
|
||||
return;
|
||||
}
|
||||
const text = await response.text();
|
||||
|
||||
titles.push(...text.split('\n'));
|
||||
refresh();
|
||||
});
|
||||
}
|
||||
loadFiles();
|
||||
|
||||
function random(max) {
|
||||
return Math.floor(Math.random()*max);
|
||||
}
|
||||
|
||||
function generate() {
|
||||
if (titles.length === 0) {
|
||||
alert("No titles left");
|
||||
return;
|
||||
}
|
||||
const title = titles.splice(random(titles.length), 1)[0];
|
||||
|
||||
document.getElementById('title').innerText = title;
|
||||
refresh();
|
||||
}
|
||||
</script>
|
||||
|
||||
<button id="generate" type="button" onclick="generate()">Generate</button>
|
||||
<div id="title">No title</div>
|
||||
<div id="num">0 Begriffe</div>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Vite App</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user