-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpersonality_test.html
More file actions
282 lines (254 loc) · 10.5 KB
/
Copy pathpersonality_test.html
File metadata and controls
282 lines (254 loc) · 10.5 KB
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>성격 테스트 페이지</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brython@3.11.0/brython.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brython@3.11.0/brython_stdlib.js"></script>
<style>
html, body {
margin: 0;
padding: 0;
font-family: sans-serif;
background-color: #f2f2f2;
}
/* HEADER */
.header {
background-color: #ffffff;
height: 50px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 16px;
box-shadow: 0 1px 4px rgba(0,0,0,0.1);
position: fixed;
top: 0;
width: 100%;
z-index: 10;
}
.menu-button {
width: 24px;
height: 18px;
cursor: pointer;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.menu-button div {
background-color: #333;
height: 3px;
border-radius: 2px;
}
.menu {
background-color: white;
width: 100%;
position: fixed;
top: 50px;
left: 0;
z-index: 9;
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.menu.show {
max-height: 300px;
}
.menu-item {
padding: 16px;
border-bottom: 1px solid #ddd;
text-decoration: none;
color: black;
display: block;
}
.header-title {
position: absolute;
left: 50%;
transform: translateX(-50%);
font-weight: bold;
font-size: 14px;
}
.header-title a {
text-decoration: none;
color: #000;
}
.container {
max-width: 480px;
margin: 50px auto 0 auto;
padding: 20px;
background-color: white;
min-height: calc(100vh - 50px);
box-sizing: border-box;
}
h2 {
text-align: center;
margin-bottom: 30px;
}
label {
display: block;
margin-top: 16px;
font-weight: bold;
}
input[type="text"],
input[type="url"] {
width: 100%;
padding: 10px;
margin-top: 6px;
border-radius: 6px;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
margin-top: 24px;
width: 100%;
padding: 12px;
background-color: #555;
color: white;
border: none;
border-radius: 6px;
font-size: 16px;
}
button:hover {
background-color: #333;
}
</style>
</head>
<body onload="brython()">
<!-- HEADER -->
<div class="header">
<div class="menu-button" id="hamburger">
<div></div>
<div></div>
<div></div>
</div>
<div class="header-title">
<a href="index.html">성격기반 랜덤여행</a>
</div>
</div>
<!-- DROPDOWN MENU -->
<div class="menu" id="menu"></div>
<!-- FORM -->
<div class="container" id="container"></div>
<script type="text/python">
from browser import document, alert, timer, window, html
import json
def setup_menu():
menu = document["menu"]
menu.clear()
user_info_str = window.sessionStorage.getItem("userInfo")
if user_info_str is None:
menu <= html.A("회원가입", href="signup.html", Class="menu-item")
menu <= html.A("로그인", href="login.html", Class="menu-item")
else:
try:
user_info = json.loads(user_info_str)
name = user_info.get("name", "회원")
greet = html.SPAN(f"{name}님 반가워요", Class="menu-item")
greet.style.cursor = "default"
greet.style.marginRight = "10px"
menu <= greet
logout = html.A("로그아웃", href="#", Class="menu-item")
logout.bind("click", on_logout)
menu <= logout
except:
on_logout(None)
questions = [
("갑자기 한달의 시간이 생긴 당신! 누구와 함께 여행을 갈까?", ("소수 정예가 마음이 편해", "다다익선! 여러 일행들과 함께 갈래"), "I", "E"),
("여행하는 중 한국인 무리를 만났어. 같은 방향으로 가자고?", ("거절", "수락"), "I", "E"),
("내가 고른 숙소는?", ("숙소 만큼은 나 혼자", "현지 친구 만날래! 게스트하우스"), "I", "E"),
("비행기에서의 모습은", ("여행지에서의 계획을 되새기고 복습", "여행지에서 일어날 일을 상상"), "S", "N"),
("여행지에서의 잠들기 전 하는 생각은", ("내일 할 일을 상기한다", "상상의 나래를 펼친다"), "S", "N"),
("새로운 음식을 먹어보고…", ("색을 보니까… 짤거같은데?", "아…사과다…"), "S", "N"),
("식당에서 부당한 대우를 받았을 때", ("일단 참는다", "따진다"), "F", "T"),
("기념품은 어떤 걸?", ("내가 사주고 싶은 걸", "원하는 걸 직접 물어본다"), "F", "T"),
("여행지에서 사고가 났다는 연락을 받았다!", ("괜찮아? ㅜㅜ", "보험 들었어?"), "F", "T"),
("여행지를 정하는 스타일은?", ("어쩐지 끌리는 곳으로", "거리,비용 등 조건 따진다"), "P", "J"),
("원래 가려던 곳이 휴관이라면?", ("새로운 곳을 찾아 떠난다", "플랜 B 완벽 준비"), "P", "J"),
("여행지에 도착했을 때", ("아 빼먹었다… 옆사람에게 빌린다", "모든 준비물이 완벽"), "P", "J"),
]
mbti_scores = {"E": 0, "I": 0, "S": 0, "N": 0, "T": 0, "F": 0, "J": 0, "P": 0}
current_index = 0
def start_test():
document["container"].clear()
show_question()
def show_question():
global current_index
if current_index >= len(questions):
show_test_result()
return
q, (opt1, opt2), left, right = questions[current_index]
container = document["container"]
container.clear()
container <= html.H2(f"Q{current_index+1}. {q}")
btn1 = html.BUTTON(opt1)
btn2 = html.BUTTON(opt2)
btn1.style.marginTop = "20px"
btn2.style.marginTop = "10px"
btn1.bind("click", lambda ev: on_answer(left))
btn2.bind("click", lambda ev: on_answer(right))
container <= btn1
container <= btn2
def on_answer(selected_trait):
global current_index
mbti_scores[selected_trait] += 1
current_index += 1
show_question()
def show_test_result():
test_result = ""
test_result += "E" if mbti_scores["E"] >= mbti_scores["I"] else "I"
test_result += "S" if mbti_scores["S"] >= mbti_scores["N"] else "N"
test_result += "T" if mbti_scores["T"] >= mbti_scores["F"] else "F"
test_result += "J" if mbti_scores["J"] >= mbti_scores["P"] else "P"
name = "당신"
mbti = test_result
user_info_str = window.sessionStorage.getItem("userInfo")
if user_info_str:
try:
user_info = json.loads(user_info_str)
except:
user_info = {}
else:
user_info = {}
user_info["mbti"] = test_result
window.sessionStorage.setItem("userInfo", json.dumps(user_info))
name = user_info.get("name", "당신")
mbti = user_info.get("mbti", test_result)
mbti_compatibility = {
"INTJ": {"best": ["ENFP", "ENTP"], "worst": ["ESFJ", "ISFJ"]},
"INFP": {"best": ["ENFJ", "ENTJ"], "worst": ["ESTP", "ESTJ"]},
"ENFP": {"best": ["INFJ", "INTJ"], "worst": ["ISTP", "ISTJ"]},
"INFJ": {"best": ["ENFP", "ENTP"], "worst": ["ESTP", "ISTP"]},
"ENFJ": {"best": ["INFP", "ISFP"], "worst": ["ISTP", "ESTP"]},
"ENTJ": {"best": ["INFP", "INTP"], "worst": ["ISFP", "INFP"]},
"INTP": {"best": ["ENTJ", "ESTJ"], "worst": ["ESFJ", "ISFJ"]},
"ENTP": {"best": ["INFJ", "INTJ"], "worst": ["ESFJ", "ISFJ"]},
"ISFP": {"best": ["ENFJ", "ESFJ"], "worst": ["INFP", "ENFP"]},
"ESFP": {"best": ["ISFJ", "ISTJ"], "worst": ["INFJ", "ENFJ"]},
"ISTP": {"best": ["ESFJ", "ESTJ"], "worst": ["ENFJ", "ENFP"]},
"ESTP": {"best": ["ISFJ", "ISTJ"], "worst": ["ENFJ", "INFJ"]},
"ISFJ": {"best": ["ESTP", "ESFP"], "worst": ["ENFJ", "ENFP"]},
"ESFJ": {"best": ["ISFP", "ISTP"], "worst": ["INFP", "ENFP"]},
"ISTJ": {"best": ["ESTP", "ESFP"], "worst": ["INFP", "ENFP"]},
"ESTJ": {"best": ["ISFP", "ISTP"], "worst": ["INFP", "INFJ"]}
}
compat_info = mbti_compatibility.get(mbti, {"best": [], "worst": []})
best_match = ", ".join(compat_info["best"])
worst_match = ", ".join(compat_info["worst"])
container = document["container"]
container.clear()
container <= html.H2(f"{name}님의 여행 MBTI는 {test_result}입니다.")
container <= html.P(f"✨ 최고의 궁합: {best_match}")
container <= html.P(f"⚠️ 최악의 궁합: {worst_match}")
def on_logout(ev):
window.sessionStorage.removeItem("userInfo")
window.location.href = "index.html"
setup_menu()
def toggle_menu(event):
menu = document["menu"]
menu.classList.toggle("show")
document["hamburger"].bind("click", toggle_menu)
start_test()
</script>
</body>
</html>