-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
81 lines (71 loc) · 2.62 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html>
<html lang="nl">
<head>
<title>Dominion Script</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="dominion.js"></script>
<script type="text/javascript" src="cookie_functions.js"></script>
<script type="text/javascript">
options = getOptionsCookie() ?? options;
const boxNameToId = (boxName) => {
const matches = boxName.match(/[a-zA-Z]/g);
return matches ? matches.join('') : '';
}
const onOptionClick = (event, boxName) => {
if (!options.allowedBoxNames) {
options.allowedBoxNames = [];
}
const otherBoxNames = options.allowedBoxNames.filter(n => n !== boxName);
if (options.allowedBoxNames.includes(boxName)) {
options.allowedBoxNames = otherBoxNames;
document.querySelector(`#${boxNameToId(boxName)}`).checked = false;
} else {
options.allowedBoxNames = [...otherBoxNames, boxName];
document.querySelector(`#${boxNameToId(boxName)}`).checked = true;
}
setOptionsCookie(options);
}
const initOptions = () => {
const optionsContainer = document.querySelector("#box-filter-options-container");
optionsContainer.replaceChildren();
for (const boxName of Object.keys(dominion.boxNames)) {
const checkBox = document.createElement("input");
checkBox.type = "checkbox";
checkBox.id = boxNameToId(boxName);
checkBox.checked = options && options.allowedBoxNames && options.allowedBoxNames.includes(boxName);
const label = document.createElement("label");
label.for = boxName;
label.innerText = dominion.boxNames[boxName];
const div = document.createElement("div");
div.onclick = (event) => onOptionClick(event, boxName);
div.classList.add('box-filter-option');
div.appendChild(checkBox);
div.appendChild(label);
optionsContainer.appendChild(div);
}
}
const generate = () => {
let output = main();
document.querySelector("#out").innerText = output;
}
fetch('dominion_nl.json')
.then(res => res.json())
.then(obj => dominion = obj)
.then(initOptions)
.catch(err => alert(`kon de dominion data niet laden: ${err.message}`));
</script>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div id="page-content">
<h1>Dominion Script</h1>
<p>Achtergrond: Barend Cornelis Koekkoek - Zomerlandschap met kasteel (1851). Deze website gebruikt functionele cookies om de opties op te slaan. </p>
<div id="options-container">
<div>Dozen</div>
<div id="box-filter-options-container"></div>
</div>
<button id="generate-game-button" onclick="generate()">Genereer Dominion-spel</button>
<p id="out"></p>
</div>
</body>
</html>