-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
211 lines (188 loc) · 7.37 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
206
207
208
209
210
211
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="HandheldFriendly" content="True" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#c7ecee">
<link rel="shortcut icon" href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABqklEQVQ4jZ2Tv0scURDHP7P7SGWh14mkuXJZEH8cgqUWcklAsLBbCEEJSprkD7hD/4BUISHEkMBBiivs5LhCwRQBuWgQji2vT7NeYeF7GxwLd7nl4knMwMDMfL8z876P94TMLt+8D0U0EggQSsAjwMvga8ChJAqxqjTG3m53AQTg4tXHDRH9ABj+zf6oytbEu5d78nvzcyiivx7QXBwy46XOi5z1jbM+Be+nqVfP8yzuD3FM6rzIs9YE1hqGvDf15cVunmdx7w5eYJw1pcGptC9CD4gBUuef5Ujq/BhAlTLIeFYuyfmTZgeYv+2nPt1a371P+Hm1WUPYydKf0lnePwVmh3hnlcO1uc7yvgJUDtdG8oy98kduK2KjeHI0fzCQINSXOk/vlXBUOaihAwnGWd8V5r1uhe1VIK52V6JW2D4FqHZX5lphuwEE7ooyaN7gjLMmKSwYL+pMnV+MA/6+g8RYa2Lg2RBQbj4+rll7uymLy3coiuXb5PdQVf7rKYvojAB8Lf3YUJUHfSYR3XqeLO5JXvk0dhKqSqQQoCO+s5AIxCLa2Lxc6ALcAPwS26XFskWbAAAAAElFTkSuQmCC" />
<title>Country Timezone Search</title>
<meta name="description" content="Search the country name or timezone to get the current date and time."/>
<link rel="preconnect" href="https://cdn.jsdelivr.net">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/[email protected]/css/pico.min.css" integrity="sha256-3V/VWRr9ge4h3MEXrYXAFNw/HxncLXt9EB6grMKSdMI=" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Encode+Sans+SC:[email protected]&display=swap" rel="stylesheet">
<style>
html, body {
min-height: 100vh;
}
body {
background-color: #a7f0fd;
color: #333;
font-family: "Encode Sans SC", sans-serif;
font-weight: 600;
padding-bottom: 20px;
}
h1, h2 {
color: #333;
font-family: "Encode Sans SC", sans-serif;
font-weight: 600;
}
h1 {
font-size: 23px;
text-align: center;
}
h2 {
font-size: 21px;
}
p {
color: #333;
font-family: "Encode Sans SC", sans-serif;
font-weight: 600;
font-size: 15px;
}
input[type="text"] {
font-family: "Encode Sans SC", sans-serif;
border-radius: 20px;
padding: 10px 20px;
border: 1px solid #faf754;
background-color: #fff;
color: #333;
}
.container {
max-width: 600px;
margin: 0px auto;
padding: 20px;
border-radius: 10px;
font-family: "Encode Sans SC", sans-serif;
}
.form-card {
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
background-color: #faf754;
font-family: "Encode Sans SC", sans-serif;
}
.btn-primary {
border-radius: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
font-family: "Encode Sans SC", sans-serif;
background-color: #2c5af1;
color: #ecdfdf;
font-weight: 700;
}
.btn-primary:hover {
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.error {
color: #dc3545;
font-size: 14px;
margin-top: 10px;
font-family: "Encode Sans SC", sans-serif;
font-weight: 700;
text-align: center;
}
.result-card {
font-family: "Encode Sans SC", sans-serif;
padding: 20px;
margin-top: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
background-color: #defce2;
}
</style>
</head>
<body>
<section>
<div class="container">
<h1 class="text-center">Country Timezone Search</h1>
<div class="form-card">
<form onsubmit="searchTime(); return false;">
<div class="input-group">
<input type="text" id="searchInput" class="form-control" pattern="[a-zA-Z, ]+" title="Enter only letters, spaces, and commas" placeholder="Country or Zone Name">
<div class="input-group-append">
<button type="submit" class="btn btn-primary">Search</button>
</div>
</div>
<p id="errorMsg" class="error"></p>
</form>
</div>
<div id="results" class="mt-2"></div><br>
</div>
</section>
<script>
const canonicalLink = document.createElement('link');
canonicalLink.rel = 'canonical';
canonicalLink.href = window.location.href;
document.head.appendChild(canonicalLink);
function searchTime() {
const searchValue = document.getElementById('searchInput').value.trim().toLowerCase();
const errorMsgElement = document.getElementById('errorMsg');
const resultsContainer = document.getElementById('results');
resultsContainer.innerHTML = '';
errorMsgElement.textContent = '';
if (searchValue === '') {
errorMsgElement.textContent = 'Please enter a country name.';
return;
}
fetch('https://time.mskian.com/database/country.json')
.then(response => response.json())
.then(data => {
const matches = [];
Object.entries(data).forEach(([country, timezones]) => {
if (country.toLowerCase().includes(searchValue) || timezones.some(tz => tz.toLowerCase().includes(searchValue))) {
matches.push({ country, timezones });
}
});
if (matches.length > 0) {
matches.forEach(match => {
const resultElement = document.createElement('div');
resultElement.classList.add('result-card');
resultElement.innerHTML = `<h2>${match.country}</h2>`;
match.timezones.forEach(timezone => {
const currentTime = new Date().toLocaleString("en-US", {timeZone: timezone});
const timeZoneName = Intl.DateTimeFormat(undefined, {timeZoneName: 'long'}).formatToParts(new Date()).find(({type}) => type === 'timeZoneName').value;
const day = new Date().toLocaleString("en-US", {timeZone: timezone, weekday: 'long'});
const emoji = getEmojiForDay(day);
const timezoneList = `<strong>${timezone}</strong>`;
resultElement.innerHTML += `<br><p>${emoji} ${day}<br><br><kbd>${currentTime}</kbd><br><br><mark>${timezoneList}</mark></p><br>`;
});
resultsContainer.appendChild(resultElement);
});
} else {
errorMsgElement.textContent = 'No matching countries found.';
}
})
.catch(error => {
console.error('Error fetching data:', error);
errorMsgElement.textContent = 'An error occurred while fetching data.';
});
}
function getEmojiForDay(day) {
switch(day.toLowerCase()) {
case 'monday':
return '📅';
case 'tuesday':
return '📆';
case 'wednesday':
return '📇';
case 'thursday':
return '📈';
case 'friday':
return '📉';
case 'saturday':
return '📊';
case 'sunday':
return '📋';
default:
return '';
}
}
document.getElementById('searchInput').addEventListener('input', function() {
document.getElementById('errorMsg').textContent = '';
});
</script>
</body>
</html>