-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.html
205 lines (159 loc) · 6.51 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
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
<!DOCTYPE html>
<html>
<head>
<link rel="canonical" href="https://letswritetw.github.io/letswrite-food-check/" />
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=0">
<title>午餐吃什麼 - August - Let's Write</title>
<meta name="description" content="午餐吃什麼?用抽獎方式來決定今天的午餐吧!由 August 開發,以 Google Sheets 當資料庫,介接 Google Map Embed API,輕鬆好管理。">
<link rel="shortcut icon" href="https://letswritetw.github.io/letswritetw/dist/img/logo_512.png"/>
<meta property="og:url" content="https://letswritetw.github.io/letswrite-food-check/" />
<meta property="og:site_name" content="Let's Write" />
<meta property="og:title" content="午餐吃什麼 - by August - Let's Write" />
<meta property="og:description" content="午餐吃什麼?用抽獎方式來決定今天的午餐吧!由 August 開發,以 Google Sheets 當資料庫,介接 Google Map Embed API,輕鬆好管理。" />
<meta property="og:image" content="https://letswritetw.github.io/letswrite-food-check/assets/img/bg-food.jpg" />
<meta itemprop="name" content="午餐吃什麼 - by August">
<meta itemprop="description" content="午餐吃什麼?用抽獎方式來決定今天的午餐吧!由 August 開發,以 Google Sheets 當資料庫,介接 Google Map Embed API,輕鬆好管理。">
<meta itemprop="image" content="https://letswritetw.github.io/letswrite-food-check/assets/img/bg-food.jpg">
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.min.css'/>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css'/>
<link rel="stylesheet" href="assets/css/main.css">
<!-- Google Tag Manager-->
<script>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-PGQ9WQT');
</script>
</head>
<body>
<!-- Google Tag Manager (noscript)-->
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-PGQ9WQT" height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
<!-- 背景圖 -->
<main class="full-block">
<!-- 主要內容 -->
<div class="main-block">
<!-- 顯示區塊 -->
<section class="god">
<h1>
<span class="wrap">
<span>午餐吃什麼呢?</span>
</span>
</h1>
</section>
<!-- 按鈕 -->
<section class="btns">
<div class="checkbox">
<p class="vegetarian">Vegetarian?</p>
<!-- 素食 -->
<div class="check">
<label class="toggle">
<input id="vage" type="checkbox" checked>
<span class="button round"></span>
</label>
</div>
</div>
<!-- start -->
<a class="btn-start" href="#">
<span class="line top -h"></span>
<span class="line right -v"></span>
<span class="line bottom -h"></span>
<span class="line left -v"></span>
</a>
</section>
<!-- 地圖 -->
<section id="map" class="map">
<iframe loading="lazy" frameborder="0" style="border:0" src="" allowfullscreen referrerpolicy="no-referrer-when-downgrade"></iframe>
</section>
</div>
</main>
<!-- github link -->
<div class="github">
<a href="https://github.com/letswritetw/letswrite-food-check">
<i class="fa fa-github" aria-hidden="true"></i>
</a>
</div>
<!-- for search -->
<div class="search-only">
<h2>
午餐吃什麼選擇器 Google Excel、Google Map Embed API
</h2>
<p>
午餐吃什麼?用抽獎方式來決定今天的午餐吧!由 August 開發,以 Google Excel 當資料庫,介接 Google Map Embed API,輕鬆好管理。
</p>
</div>
<script>
// Maps Embed API、Google Sheets API 的 金鑰
// 可由 https://console.developers.google.com/apis 申請
const embedApiKey = 'AIzaSyDtu-vNL3cTLQF_Tongrtckzfs8LS4ClkM';
const uri = 'https://sheets.googleapis.com/v4/spreadsheets/11wLZL0bNoD7ZQwfN3Tkx41YB6IgLbv4ftsrxywA0114/values/lets-write?alt=json&key=' + embedApiKey;
const duration = 2000; // 拉霸效果執行多久
fetch(uri)
.then(res => res.json())
.then(data => {
let vages = []; // 素
let meats = []; // 葷
// 分葷、素,塞入陣列
const d = data.values, len = d.length;
for(let i = 0; i < len; i++) {
d[i][1] === '是' ? vages.push(d[i][0]) : meats.push(d[i][0]);
}
// 點擊按鈕後執行
let r; // 亂數
let max, min; // 陣列的最大、小值
let txt; // 結果
// 地圖
const map = document.querySelector('#map iframe');
// 按鈕
const btn = document.querySelector('.btn-start');
btn.addEventListener('click', e => {
e.preventDefault();
// 選店家 fn
const chooseShop = toggle => {
// 取亂數 fn
r = () => {
max = toggle.length - 1;
min = 0;
return Math.floor(Math.random() * (max - min + 1)) + min;
};
// 清空、插入選項
let input = document.querySelector('.wrap');
input.innerHTML = '';
for(let i = 0; i < toggle.length; i++) {
input.insertAdjacentHTML('beforeend', '<span>' + toggle[i] + '</span>');
}
// 禁止按鈕再被點擊
e.target.classList.add('not-allow');
// 加入動畫 class name
const list = document.querySelectorAll('.wrap > span');
Array.prototype.forEach.call(list, l => l.classList.add('span-' + (toggle.length - 1)));
// 亂數決定中選店家
txt = toggle[r()];
list[0].innerText = txt;
// 移除動畫
setTimeout(() => {
// 停止拉霸動畫
Array.prototype.forEach.call(list, l => l.removeAttribute('class'));
// 改變地圖位置
map.src = 'https://www.google.com/maps/embed/v1/place?key=' + embedApiKey + '&q=' + txt;
}, duration);
// 顯示地圖
map.addEventListener('load', () => {
map.classList.remove('hidden');
e.target.classList.remove('not-allow');
}, false);
};
// 地圖先消失
map.classList.add('hidden');
// 判斷葷素後,開始執行
let vage = document.getElementById('vage');
vage.checked ? chooseShop(vages) : chooseShop(meats);
}, false);
})
</script>
</body>
</html>