-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
82 lines (70 loc) · 2.72 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>하이메디 점심요정</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, inistial-scale=1.0, viewport-fit=cover">
<link rel="icon" href="favicon.ico">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
</head>
<body class="bg-warning bg-gradient">
<div class="container vh-100 d-flex justify-content-center align-items-center">
<div id="randomBtn" class="btn">
<img class="emoji"/>
<h4 class="text-white fw-bold">눌러서 점심 찾기</h4>
</div>
<div id="spinner" class="spinner-border text-success" role="status" hidden>
<span class="visually-hidden">Loading...</span>
</div>
</div>
</body>
<style>
.emoji {
width: 200px;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', () => {
document.querySelector('.emoji').setAttribute('src', randomEmoji())
const randomBtn = document.querySelector('#randomBtn')
const spinner = document.querySelector('#spinner')
randomBtn.addEventListener('click', async () => {
randomBtn.hidden = true
spinner.hidden = false
const restaurants = await getRestaurants()
const picked = restaurants[Math.floor(Math.random() * restaurants.length)];
randomBtn.hidden = false
spinner.hidden = true
location.href = picked.place_url
})
})
async function getRestaurants() {
const baseUrl = 'https://dapi.kakao.com/v2/local/search/keyword.json?y=37.4996977&x=127.023382&radius=500'
const url = `${baseUrl}&query=${encodeURIComponent('강남역 점심')}&page=${randomPage()}`
const authorization = 'KakaoAK a6e6b1da205e7e44358765185414aa27'
const res = await fetch(url, {
headers: {
Authorization: authorization
}
})
const json = await res.json()
return json.documents
}
function randomEmoji() {
const START = 1
const END = 4
return `assets/emoji_${Math.floor((Math.random() * (END - START + 1)) + START)}.gif`
}
function randomPage() {
const START = 1
const END = 40
return Math.floor((Math.random() * (END - START + 1)) + START)
}
</script>
</html>