-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.js
More file actions
154 lines (142 loc) · 5.2 KB
/
chat.js
File metadata and controls
154 lines (142 loc) · 5.2 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
// 오늘 날짜 표시
var todayDateElement = document.getElementById('today-date');
var today = new Date();
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
todayDateElement.innerText = today.toLocaleDateString('ko-KR', options);
// 팝업창 표시 함수
function openPopup(popupClass) {
var popup = document.getElementsByClassName(popupClass)[0];
popup.style.display = "block";
}
// 팝업창 닫기 함수
function closePopup(popupClass) {
var popup = document.getElementsByClassName(popupClass)[0];
popup.style.display = "none";
}
// 닫기 버튼 클릭 시 팝업창 닫기
document.querySelectorAll(".close-button").forEach(function(closeButton) {
closeButton.addEventListener("click", function() {
closePopup(this.closest(".popup").classList[0]);
});
});
// 방 만들기 버튼 클릭 시 팝업창 열기
document.querySelector(".create-room-button").addEventListener("click", function() {
openPopup("popup");
});
// 초대코드 버튼 클릭 시 팝업창 열기
document.querySelector(".invite-code-button").addEventListener("click", function() {
openPopup("invite-popup");
});
// 초대코드 확인 함수
function checkInviteCode() {
var inviteCode = document.getElementById("invite-code").value.trim();
var isValid = isValidInviteCode(inviteCode);
if (isValid) {
closePopup("invite-popup");
} else {
document.getElementById("invite-error-msg").style.display = "block";
}
}
// 초대코드 유효성 검사 함수
function isValidInviteCode(code) {
// 초대코드가 비어 있는 경우 유효하지 않음
if (code === "") {
return false;
}
// 영문과 숫자가 섞여 있는지 확인
var hasLetter = false;
var hasNumber = false;
for (var i = 0; i < code.length; i++) {
var charCode = code.charCodeAt(i);
if ((charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122)) {
hasLetter = true; // 영문자가 있는 경우
} else if (charCode >= 48 && charCode <= 57) {
hasNumber = true; // 숫자가 있는 경우
}
}
// 영문과 숫자가 모두 포함되어 있으면 유효함
return hasLetter && hasNumber;
}
// 문서 로드 시 팝업창 숨기기
window.onload = function() {
document.querySelectorAll(".popup").forEach(function(popup) {
popup.style.display = "none";
});
};
// 팀 이름 저장 변수
let teamName = '';
// 팀 생성 버튼 클릭 시 코드 생성 및 팝업창 열기
document.querySelector(".create-team-button").addEventListener("click", function() {
teamName = document.querySelector("#popup input[type='text']").value.trim(); // 팀 이름 입력값 저장
if (teamName !== "") {
var generatedCode = generateRandomCode();
document.getElementById("generated-code").textContent = generatedCode;
openPopup("code-popup");
}
});
// My Team 목록에 팀 이름 추가하는 함수
function addTeamToList() {
const teamListContainer = document.querySelector('.my-team-container p');
teamListContainer.textContent = teamName;
}
// 팀 생성 버튼 클릭 시 코드 생성 및 팝업창 열기
document.querySelector(".create-team-button").addEventListener("click", function() {
var roomName = document.querySelector("#popup input[type='text']").value;
if (roomName.trim() !== "") {
var generatedCode = generateRandomCode();
document.getElementById("generated-code").textContent = generatedCode;
openPopup("code-popup");
addTeamToList(); // My Team 목록에 팀 이름 추가
}
});
// 랜덤 코드 생성 함수
function generateRandomCode() {
var characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var codeLength = 6; // 코드 길이를 6자리로 변경
var code = "";
for (var i = 0; i < codeLength; i++) {
code += characters.charAt(Math.floor(Math.random() * characters.length));
}
return code;
}
// 코드 복사 함수
function copyCode() {
var generatedCode = document.getElementById("generated-code").textContent;
navigator.clipboard.writeText(generatedCode)
.then(function() {
console.log("Code copied to clipboard: " + generatedCode);
})
.catch(function(error) {
console.error("Failed to copy code to clipboard: ", error);
});
closePopup("code-popup");
}
function openPopup(popupId) {
var popup = document.getElementById(popupId);
popup.style.display = "block";
}
// 팝업창 닫기 함수
function closePopup(popupId) {
var popup = document.getElementById(popupId);
popup.style.display = "none";
}
// 방 만들기 버튼 클릭 시 팝업창 열기
document.querySelector(".create-room-button").addEventListener("click", function() {
openPopup("popup");
});
// 초대코드 버튼 클릭 시 팝업창 열기
document.querySelector(".invite-code-button").addEventListener("click", function() {
openPopup("invite-popup");
});
// 닫기 버튼 클릭 시 팝업창 닫기
document.querySelectorAll(".close-button").forEach(function(closeButton) {
closeButton.addEventListener("click", function() {
closePopup(this.closest(".popup").id);
});
});
// 문서 로드 시 팝업창 숨기기
window.onload = function() {
document.querySelectorAll(".popup").forEach(function(popup) {
popup.style.display = "none";
});
};