-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
128 lines (98 loc) · 3.2 KB
/
main.js
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
const QUOTES = "quotes";
function getTime() {
const time = document.querySelector(".time");
const newDate = new Date();
const hours = String(newDate.getHours()).padStart(2, "0");
const minutes = String(newDate.getMinutes()).padStart(2, "0");
const seconds = String(newDate.getSeconds()).padStart(2, "0");
if (seconds.toString().length === 1) {
seconds = "0" + seconds;
}
// time.innerText = hours + ":" + minutes + ":" + seconds;
time.innerText = `${hours} : ${minutes} : ${seconds}`;
}
getTime();
setInterval(getTime, 1000);
function getQuotes() {
const quotesMsg = document.querySelector(".quotesMsg");
let savedQuotes = localStorage.getItem(QUOTES);
if (!savedQuotes) {
localStorage.setItem(
QUOTES,
JSON.stringify([
"열심히 살지맙시다.",
"그래도 열심히 살아야지.",
"열심히 살면 뭐해~",
"열심히 살면 반드시 빛이 온다.",
])
);
savedQuotes = localStorage.getItem(QUOTES);
}
let quotesArray = JSON.parse(savedQuotes);
quotesMsg.innerText =
quotesArray[Math.floor(Math.random() * quotesArray.length)];
}
getQuotes();
function onClickAdd() {
const newQuotes = document.querySelector(".newQuotes");
newQuotes.style.display = "inline-block";
}
function onClickRegist() {
const quotesMsg = document.querySelector(".quotesMsg");
const newQuotes = document.querySelector(".newQuotes");
const newQuotesInput = document.querySelector(".newQuotesInput");
if (!newQuotesInput.value) {
return;
}
let savedQuotes = localStorage.getItem(QUOTES);
let quotesArray = JSON.parse(savedQuotes);
quotesArray.push(newQuotesInput.value);
localStorage.setItem(QUOTES, JSON.stringify(quotesArray));
quotesMsg.innerHTML = `<span style="color:red;">${newQuotesInput.value}</span>`;
newQuotes.style.display = "none";
}
let isLoading = false;
async function onClickSearch() {
// async 비동기 , await 사용하기 위해
const searchInput = document.querySelector(".searchInput");
const searchResult = document.querySelector(".searchResult");
if (!searchInput.value) return;
if (!isLoading) return;
isLoading = true;
const question = searchInput.value;
searchInput.value = "검색 중 입니다... 잠시만 기다려주세요.";
// 프론트엔드에서 백엔드로 보내는 소스
const response = await axios.post(
/* get 요청 post 요청.
백엔드에서 post요청을 받게 설정을 해둬서 post로
await 잠시 기다려달리
*/
"https://holy-fire-2749.fly.dev/chat",
{
question,
},
{
headers: {
"Content-Type": "application/json",
Authorization: "Bearer BLOCKCHAINSCHOOL3",
},
}
);
if (response.status == 200) {
searchResult.style.display = "inline";
searchResult.innerText = response.data.choices[0].message.content;
}
searchInput.value = "";
isLoading = false;
}
function onClickToggle(value) {
const nft = document.querySelector(".nft");
const nftView = document.querySelector(".nftView");
if (value) {
nft.style.display = "inline-block";
nftView.style.display = "none";
} else {
nft.style.display = "none";
nftView.style.display = "inline-block";
}
}