-
Notifications
You must be signed in to change notification settings - Fork 0
/
paper.html
264 lines (261 loc) · 13 KB
/
paper.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<title>2023魔法节小纸条</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="assets/common.css">
<link rel="stylesheet" type="text/css" href="assets/sticky.css">
<link rel="stylesheet" type="text/css" href="assets/button.css">
<link rel="stylesheet" type="text/css" href="assets/chest.css">
<link rel="stylesheet" type="text/css" href="assets/paper.css">
<script lang="javascript">
function santinize(str) { return str.trim().replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("\'", "'").replaceAll("&", "&").replaceAll("\\", "\").replaceAll("\/", "/"); }
function postPaper(name, info, email, color) {
const req = new XMLHttpRequest();
const content = JSON.stringify({
"name": santinize(name),
"info": santinize(info),
"email": santinize(email),
"color": color,
});
req.open("POST", "http://182.92.67.83:10719/paper/post", true);
req.setRequestHeader("content-type", "application/json");
req.onreadystatechange = function () {
if (req.readyState == 4) {
if (req.status == 200) {
const res = JSON.parse(req.responseText);
if (res.code == 10000) {
//Display animation
document.getElementById('container').classList.add('shrink');
setTimeout(function () {
document.getElementById("middle").classList.remove("open");
}, 1000);
} else {
//Display retry button
}
} else {
//Display retry button
}
}
};
req.send(content);
}
function changeColor() {
document.getElementsByName("color").forEach(function (value, key, parent) {
if (value.checked) {
switch (value.value) {
case "yellow":
document.getElementById("main").style.backgroundColor = "var(--yellow)";
document.getElementById("submit").className = "submit btn-gradient large " + value.value;
break;
case "blue":
document.getElementById("main").style.backgroundColor = "var(--blue)";
document.getElementById("submit").className = "submit btn-gradient large " + value.value;
break;
case "purple":
document.getElementById("main").style.backgroundColor = "var(--purple)";
document.getElementById("submit").className = "submit btn-gradient large " + value.value;
break;
case "green":
document.getElementById("main").style.backgroundColor = "var(--green)";
document.getElementById("submit").className = "submit btn-gradient large " + value.value;
break;
case "red":
document.getElementById("main").style.backgroundColor = "var(--red)";
document.getElementById("submit").className = "submit btn-gradient large " + value.value;
break;
default:
break;
}
}
});
}
function submit() {
const info = document.getElementById("info");
const name = document.getElementById("name");
const email = document.getElementById("email");
var color;
document.getElementsByName("color").forEach(function (value, key, parent) {
if (value.checked) {
switch (value.value) {
case "yellow":
color = "#ffc";
break;
case "blue":
color = "#cff";
break;
case "purple":
color = "#ccf";
break;
case "green":
color = "#cfc";
break;
case "red":
color = "#fcc";
break;
default:
break;
}
}
});
if (name.innerText == "20个字以内" || info.innerText == "200个字以内,尽量不要超过5行") {
return;
}
document.getElementById("middle").classList.add("open");
document.getElementsByName("color").forEach(function (value, key, parent) { value.disabled = true; });
postPaper(name.innerText, info.innerText, email.innerText, color);
}
function getPaper() {
const req = new XMLHttpRequest();
req.open("GET", "http://182.92.67.83:10719/paper/get", true);
req.onreadystatechange = function () {
if (req.readyState == 4) {
if (req.status == 200) {
const res = JSON.parse(req.responseText);
//Process paper
document.getElementById("name").innerText = res.name;
document.getElementById("info").innerText = res.info;
document.getElementsByName("color").forEach(function (value, key, parent) {
if (value.checked) { value.checked = false; }
var colorName;
switch (res.color) {
case "#ffc":
colorName = "yellow";
break;
case "#cff":
colorName = "blue";
break;
case "#ccf":
colorName = "purple";
break;
case "#cfc":
colorName = "green";
break;
case "#fcc":
colorName = "red";
break;
default:
break;
}
if (value.value == colorName) {
value.checked = true;
document.getElementById("main").style.backgroundColor = "var(--" + colorName + ")";
document.getElementById("home").classList.add(colorName);
}
});
document.getElementById("container").classList.remove("shrink");
setTimeout(function () {
document.getElementById("bottom").classList.remove("open");
}, 1000);
} else {
//Display retry button
}
}
};
req.send();
}
function random() {
document.getElementById("bottom").classList.add("open");
document.getElementById("hidden1").hidden = true;
document.getElementById("hidden2").hidden = true;
document.getElementById("return").hidden = false;
getPaper();
}
</script>
</head>
<body>
<!-- Chest starts -->
<div style="position:fixed;right:10%;bottom:10%;" class="chest">
<div class="chest__panel chest__panel--back"></div>
<div class="chest__panel chest__panel--front">
<div class="chest__panel chest__panel--front-frame"></div>
</div>
<div class="chest__panel chest__panel--top"></div>
<div class="chest__panel chest__panel--bottom"></div>
<div class="chest__panel chest__panel--left"></div>
<div class="chest__panel chest__panel--right"></div>
<div class="chest-drawer chest-drawer--top">
<details id="top">
<summary></summary>
</details>
<div class="chest-drawer__structure">
<div class="chest-drawer__panel chest-drawer__panel--left"></div>
<div class="chest-drawer__panel chest-drawer__panel--right"></div>
<div class="chest-drawer__panel chest-drawer__panel--bottom"></div>
<div class="chest-drawer__panel chest-drawer__panel--back"><b>SubIT</b></div>
</div>
</div>
<div class="chest-drawer chest-drawer--middle">
<details id="middle">
<summary></summary>
</details>
<div class="chest-drawer__structure">
<div class="chest-drawer__panel chest-drawer__panel--left"></div>
<div class="chest-drawer__panel chest-drawer__panel--right"></div>
<div class="chest-drawer__panel chest-drawer__panel--bottom"></div>
<div class="chest-drawer__panel chest-drawer__panel--back"><b>Inbox</b></div>
</div>
</div>
<div class="chest-drawer chest-drawer--bottom">
<details id="bottom">
<summary></summary>
</details>
<div class="chest-drawer__structure">
<div class="chest-drawer__panel chest-drawer__panel--left"></div>
<div class="chest-drawer__panel chest-drawer__panel--right"></div>
<div class="chest-drawer__panel chest-drawer__panel--bottom"></div>
<div class="chest-drawer__panel chest-drawer__panel--back"><b>Outbox</b></div>
</div>
</div>
</div>
<!-- Chest ends -->
<div class="container" id="container">
<div class="main sticky tape" style="background-color:var(--yellow);" id="main">
<br>
<b>昵称*:</b>
<div contenteditable="true" style="display: inline;" id="name"
onkeydown="if(event.keyCode==13)return false;"
onclick="if(event.currentTarget.innerText=='20个字以内')event.currentTarget.innerText=''"
onblur="if(event.currentTarget.innerText.length==0)event.currentTarget.innerText='20个字以内'">20个字以内</div>
<div id="hidden1">
<b>E-mail:</b>
<div contenteditable="true" style="display: inline;" id="email"
onkeydown="if(event.keyCode==13)return false;"
onclick="if(event.currentTarget.innerText=='请使用有效的E-mail格式')event.currentTarget.innerText=''"
onblur="if(event.currentTarget.innerText.length==0)event.currentTarget.innerText='请使用有效的E-mail格式'">
请使用有效的E-mail格式</div>
</div>
<br>
<b>正文*:</b>
<br>
<div contenteditable="true" style="display: inline;" id="info"
onblur="if(event.currentTarget.innerText.length==0)event.currentTarget.innerText='200个字以内,尽量不要超过5行'"
onclick="if(event.currentTarget.innerText=='200个字以内,尽量不要超过5行')event.currentTarget.innerText=''">
200个字以内,尽量不要超过5行</div>
<div id="hidden2">
<a class="submit btn-gradient large yellow" id="submit" onclick="submit()"><b>提交</b></a>
</div>
<div id="return" hidden>
<a class="return btn-gradient large" href="index.html" id="home">返回主页</a>
</div>
</div>
</div>
<div class="settings sticky tape">
<b>便签颜色</b><br>
<div onchange="changeColor()">
<input type="radio" name="color" value="yellow" checked>黄色</input>
<input type="radio" name="color" value="blue">蓝色</input>
<input type="radio" name="color" value="purple">紫色</input>
<input type="radio" name="color" value="green">绿色</input>
<input type="radio" name="color" value="red">红色</input>
</div>
</div>
<div class="sticky tape success">
小纸条提交成功,谢谢你的参与!
<br>
点击按钮可以抽一张来自其他人的小纸条
<a class="random btn-gradient large yellow" onclick="random()">抽一张</a>
</div>
</body>
</html>