-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
191 lines (179 loc) · 4.8 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!DOCTYPE html><html lang="ja"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><link rel="icon" href="data:">
<title>こみかるメンバーBINGO</title>
</head><body>
<h1>こみかるメンバーBINGO</h1>
<main>
<div id=divbingo></div>
<h2>メンバーに会ったらオープン!</h2>
<div id=divmember></div>
</main>
<hr>
<button id=btnreset>BINGOカードをリセットする</button>
<hr>
DATA: <a href=https://code4fukui.github.io/comical/member.csv>こみかるメンバーオープンデータ(CSV)</a> - <a href=https://www.instagram.com/comicalyouth/>こみかる ユース福井(@comicalyouth)</a><br>
<a href=https://github.com/code4fukui/comical/>src on GitHub</a><br>
<script type="module">
import { CSV } from "https://code4fukui.github.io/CSV/CSV.js";
import { rnd } from "https://js.sabae.cc/rnd.js";
import { shuffle } from "https://js.sabae.cc/shuffle.js";
import isMobile from "https://code4fukui.github.io/isMobile/isMobile.js";
const base = "https://code4fukui.github.io/comical/";
const members = await CSV.fetchJSON("./member.csv");
//console.log(members);
//members.length = 5; // for test
const cr = (tag, parent) => {
const c = document.createElement(tag);
if (parent) parent.appendChild(c);
return c;
};
const btns = [];
for (let i = 0; i < members.length; i++) {
const m = members[i];
const div = cr("div", divmember);
const a = cr("a", div);
a.setAttribute("href", m.url);
a.setAttribute("target", "_blank");
const img = new Image();
img.src = m.img;
a.appendChild(img);
const btn = cr("button", div);
if (isMobile(window.navigator).any) {
btn.innerHTML = m.name + "に<br>会った!";
} else {
btn.textContent = m.name + "に会った!";
}
btn.targetName = m.name;
btns.push(btn);
}
const supporters = [
"img/lpa.jpg",
"img/smileactive.jpg",
];
const makeBingoCard = () => {
const wbingo = 5;
const bingo = [];
if (members.length <= wbingo * wbingo - 1) {
for (const m of members) {
bingo.push({ open: false, name: m.name, img: m.img });
}
const members2 = members.map(i => i);
shuffle(members2);
for (let i = 0; i < wbingo * wbingo - 1 - members.length; i++) {
const m = members2[i % members2.length];
bingo.push({ open: false, name: m.name, img: m.img });
}
console.log(bingo.length);
} else {
const members2 = members.map(i => i);
shuffle(members2);
for (let i = 0; i < wbingo * wbingo - 1; i++) {
const m = members2[i];
bingo.push({ open: false, name: m.name, img: m.img });
}
}
shuffle(bingo);
bingo.splice(12, 0, { open: true, name: "こみかる", img: base + "img/comical.jpg" });
console.log(bingo);
return bingo;
};
const showBingoCard = (bingo) => {
divbingo.innerHTML = "";
for (let i = 0; i < 5; i++) {
const div = cr("div", divbingo);
div.textContent = "BINGO"[i];
div.className = "bingo";
}
for (let i = 0; i < bingo.length; i++) {
const b = bingo[i];
const div = cr("div", divbingo);
const img = new Image();
img.src = b.open ? b.img : base + supporters[i % supporters.length];
img.style.filter = b.open ? "" : "grayscale(1)";
div.appendChild(img);
div.onclick = () => {
if (b.open) {
alert(b.name);
}
};
}
};
const loadBingoCard = () => {
const s = localStorage.getItem("comical_bingo");
if (!s) return null;
return JSON.parse(s);
};
const saveBingoCard = (bingo) => {
localStorage.setItem("comical_bingo", JSON.stringify(bingo));
};
const resetBingoCard = () => {
localStorage.removeItem("comical_bingo");
};
const bingo = loadBingoCard() || makeBingoCard();
//const bingo = makeBingoCard();
showBingoCard(bingo);
saveBingoCard(bingo);
btns.forEach(btn => {
btn.onclick = () => {
const b = bingo.find(b => b.name == btn.targetName);
if (b.open) {
alert(b.name + "に再会!");
} else {
bingo.filter(b => b.name == btn.targetName).forEach(b => b.open = true);
saveBingoCard(bingo);
alert(b.name + "に会った!");
showBingoCard(bingo);
}
scrollTo({
top: divbingo.offsetTop,
behavior: "smooth"
});
}
});
btnreset.onclick = () => {
if (confirm("BINGOカード、リセットしちゃう?")) {
resetBingoCard();
location.reload();
}
};
</script>
<style>
body {
font-family: sans-serif;
text-align: center;
color: #005aac;
}
#divmember > div {
display: inline-block;
margin: .4vw;
}
#divmember img {
width: 30vw;
display: block;
}
#divmember button {
display: inline-block;
margin: .3em 0 .8em 0;
}
#divbingo {
width: 80vw;
display: inline-block;
}
#divbingo .bingo {
width: 15vw;
font-size: 4vw;
}
#divbingo > div {
display: inline-block;
margin: .4vw;
}
#divbingo img {
width: 15vw;
}
#btnreset {
font-size: 80%;
}
a {
color: gray !important;
}
</style>
</body></html>