blob: 43e51c40b6f2dcccf659eb551f88f74d4e73cc63 (
plain) (
blame)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:title" content="Cadeaux de noël 2025"/>
<meta property="og:description" content="À qui offrir le cadeau de noël?"/>
<meta property="og:image" content="/static/favicon.ico" />
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css">
<style>
h1 {
display: flex;
justify-content: center;
}
button {
font-size: 1em;
}
#buttons {
margin: 1.5em;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
gap: 1em;
}
body {
display: flex;
justify-content: center;
align-items: center;
height: 50vh;
}
span#name {
color: blue;
}
</style>
<script>
let people =
[{{ range .People }}
{"name": "{{.Name}}", "other": {{.Other}}}, {{ end }}
];
let page1_html = `
<div>
<h1>Qui es-tu?</h1>
<div id="buttons">
{{ range .People }}
<button>{{ .Name }}</button>
{{ end }}
</div>
</div>
`;
let local_storage_key = "clicked_{{.Seed}}";
function setPage1() {
document.body.innerHTML = page1_html;
let buttons = document.querySelectorAll("button");
for(let index = 0; index < buttons.length; index += 1)
{
let button = buttons[index];
button.addEventListener("click", function(event) {
event.preventDefault();
let name = button.innerText;
let person = null;
for(let person_index = 0; person_index < people.length; person_index += 1)
{
if(people[person_index].name === name)
{
person = people[person_index];
break;
}
}
{{ if false }}
fetch('/person/', {
method: 'POST',
headers:
{
'Content-Type': 'application/x-www-form-urlencoded'
},
body: "name=" + person.name
})
.then(function(response) {
response.text().
then(function(text_response) {
if(text_response !== 'ok') {
console.log("Error");
}
})
})
.catch(error => console.error('Error:', error));
{{ end }}
document.body.innerHTML = `
<h1>Tu es bien ${person.name}?</h1>
<div id="buttons">
<button id="yes">Oui</button>
<button id="no">Non</button>
</div>`;
let yes_button = document.getElementById("yes");
let no_button = document.getElementById("no");
yes_button.addEventListener("click", function(event) {
event.preventDefault();
let other_person = people[person.other];
document.body.innerHTML = `<h1>Tu as <span id="name">${other_person.name}</span>.</h1>`;
localStorage.setItem(local_storage_key, other_person.name);
});
no_button.addEventListener("click", function(event) {
event.preventDefault();
setPage1();
});
}); // button click even listener
}
}
window.onload = function() {
let clicked = localStorage.getItem(local_storage_key);
if(!clicked)
{
setPage1();
}
else
{
document.body.innerHTML = `<h1>Tu as déjà choisi.</h1>`;
}
};
</script>
</head>
<body>
</body>
</html>
|