-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
325 lines (305 loc) · 14.9 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<!DOCTYPE html>
<html lang="en">
<head>
<title>Check CoWIN vaccine center(s) availability</title>
<meta charset="utf-8" />
<meta name="description" content="Quick way to check CoWIN vaccine center(s) availability.">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap-select.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/bootstrap-table.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap-select.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/bootstrap-table.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/min/moment.min.js"></script>
</head>
<body>
<div class="container">
<br />
<div class="page-header">
<h2>Check CoWIN vaccine center(s) availability</h2>
</div>
<br />
<form>
<div class="form-row">
<div class="col-auto">
<label class="form-check-label mb-3 font-weight-bold mr-2">Age </label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input mb-3" type="checkbox" id="age18" value="18" checked />
<label class="form-check-label mb-3" for="age18">18+</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input mb-3" type="checkbox" id="age45" value="45" />
<label class="form-check-label mb-3" for="age45">45+</label>
</div>
</div>
<div class="form-row">
<div class="col-auto">
<label class="form-check-label mb-3 font-weight-bold mr-2">Fees </label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input mb-3" type="checkbox" id="free" value="Free" checked />
<label class="form-check-label mb-3" for="free">Free</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input mb-3" type="checkbox" id="paid" value="Paid" />
<label class="form-check-label mb-3" for="paid">Paid</label>
</div>
</div>
<div class="form-row">
<div class="col-auto">
<label class="form-check-label mb-3 font-weight-bold mr-2">Search By</label>
</div>
<div class="form-check form-check-inline">
<input id="searchbypincode" class="form-check-input mb-3" type="radio" name="searchBy"
value="pincode" checked />
<label class="form-check-label mb-3" for="searchpincode">Pincode</label>
</div>
<div class="form-check form-check-inline">
<input id="searchbydistrict" class="form-check-input mb-3" type="radio" name="searchBy"
value="district" />
<label class="form-check-label mb-3" for="searchdistrict">District</label>
</div>
</div>
<div class="form-row">
<div id="pincodeGroup" class="col-auto">
<input id="pincode" class="form-control mb-3" type="text" placeholder="Pincode" />
</div>
<div id="districtGroup" class="col-auto d-none">
<select id="selectState" class="form-control selectpicker mb-3 border" data-live-search="true"
data-size="10" data-width="250px" data-style="btn-default" title="Select state">
</select>
<select id="selectDistrict" class="form-control selectpicker mb-3 border" data-live-search="true"
data-size="10" data-width="250px" data-style="btn-default" title="Select district">
</select>
</div>
<div class="col-auto">
<button id="btnCheckAvailability" class="btn btn-success mb-3" type="button"
onclick='btnCheckAvailabilityCall()'>Check
availability</button>
</div>
</div>
<div class="form-row">
<div class="col-auto">
<div class="form-check form-check-inline">
<input id="autocheck" class="form-check-input mb-3" type="checkbox" />
<label class="form-check-label mb-3" for="autocheck">Auto check after every 1 minute (Auto
check will be disabled, once center is available.)</label>
</div>
</div>
</div>
<div class="form-row">
<div class="col-auto">
<div class="form-check form-check-inline">
<input id="audioalert" class="form-check-input mb-3" type="checkbox" />
<label class="form-check-label mb-3" for="audioalert">Audio alert when center is available. <a
href="#" onclick='audioalert()'>click here to play audio sample</a> </label>
</div>
</div>
</div>
</form>
<p>Only available center(s) will be displayed.</p>
<div id="notAvailableMessage" class="alert alert-danger d-none" role="alert">
Center not available!
</div>
<div id="tablediv" class="table-responsive d-none">
<table id="table" class="table-striped" data-search="true" data-show-toggle="true"
data-show-fullscreen="true" data-show-columns="true" data-sortable="true">
<thead>
<tr>
<th data-field="centerName" data-sortable="true">Center Name</th>
<th data-field="date" data-sortable="true">Date</th>
<th data-field="availableCapacity" data-sortable="true">Availability</th>
<th data-field="age" data-sortable="true">Age</th>
<th data-field="vaccine_fees" data-sortable="true" data-formatter="VaccineFeesFormatter">Vaccine
- Fees</th>
<th data-field="googlemaplink" data-formatter="LinkFormatter">Google Map</th>
</tr>
</thead>
</table>
</div>
</div>
</body>
<script>
function LinkFormatter(value) {
return "<a href='" + value + "' target='_blank'>View Map</a>";
}
function VaccineFeesFormatter(value) {
if (value) {
value.push(value[0])
val = "";
value.forEach((vaccineFee) => {
val += vaccineFee.vaccine + " - " + vaccineFee.fee + "\n";
});
return val;
}
else
return "-";
}
$("#table").bootstrapTable({
data: [],
autoRefresh: true,
});
var timer = null;
function btnCheckAvailabilityCall() {
if (timer) {
window.clearTimeout(timer);
timer = null;
}
var isSearchByPincode = document.getElementById("searchbypincode").checked;
const audioAlertEnable = document.getElementById("audioalert").checked;
if (isSearchByPincode) {
var dataValue = document.getElementById("pincode").value.trim();
} else {
var dataValue = document.getElementById("selectDistrict").value;
}
const isValidData = (isSearchByPincode && dataValue?.length == 6) || (!isSearchByPincode && dataValue)
if (isValidData) {
let date = moment(new Date()).format("DD");
date = Number(date) + 1;
var url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/" + (isSearchByPincode ? "calendarByPin?pincode" : "calendarByDistrict?district_id") + "=" + dataValue + "&date=0" + date +"-05-2021";
var availabilityData = [];
$.ajax({
method: "GET",
url: url,
contentType: "application/json",
dataType: 'json',
success: function (responseJson) {
if (responseJson.centers) {
var centers = responseJson["centers"];
var age18Value = document.getElementById("age18").checked ? document.getElementById("age18").value : null;
var age45Value = document.getElementById("age45").checked ? document.getElementById("age45").value : null;
var freeValue = document.getElementById("free").checked ? document.getElementById("free").value : null;
var paidValue = document.getElementById("paid").checked ? document.getElementById("paid").value : null;
centers.forEach((center) => {
if (center.fee_type == freeValue || center.fee_type == paidValue) {
center.sessions.forEach((session) => {
if (
session.available_capacity > 0 &&
(session.min_age_limit == age18Value || session.min_age_limit == age45Value)
) {
var availableSession = {
centerName: center.name + " - " + center.block_name + " - " + center.pincode + " (" + center.fee_type + ")",
date: session.date,
availableCapacity: session.available_capacity,
age: session.min_age_limit,
vaccine_fees: center.vaccine_fees,
googlemaplink: "https://www.google.com/maps/search/" + center.name + " " + center.pincode,
};
availabilityData.push(availableSession);
}
});
}
});
}
if (availabilityData.length == 0) {
$("#notAvailableMessage").removeClass('d-none');
$("#tablediv").addClass('d-none');
} else {
$("#notAvailableMessage").addClass('d-none');
$("#tablediv").removeClass('d-none');
if (audioAlertEnable)
audioalert();
document.getElementById("autocheck").checked = false;
}
$('#table').bootstrapTable("load", availabilityData);
},
error: function (jqxhr, textStatus, error) {
if (jqxhr.status == 400) {
alert("Invalid pincode or district!");
}
},
complete: function () {
if (document.getElementById("autocheck").checked)
timer = setTimeout(btnCheckAvailabilityCall, 1000 * 60 * 1);
}
})
} else {
alert("Invalid pincode or district!");
}
};
$('#selectState').on('changed.bs.select', function (e, clickedIndex, isSelected, previousValue) {
if (isSelected) {
$.ajax({
type: "GET",
url: "https://cdn-api.co-vin.in/api/v2/admin/location/districts/" + this.value,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$('#selectDistrict').empty();
$.each(data.districts, function () {
var options = "<option " + "value='" + this.district_id + "'>" + this.district_name + "";
$("#selectDistrict").append(options);
});
$('#selectDistrict').selectpicker('refresh');
}
});
}
});
$('input[type=radio][name=searchBy]').change(function () {
if (this.value == 'district') {
$("#pincodeGroup").addClass('d-none');
$("#districtGroup").removeClass('d-none');
}
else {
$("#pincodeGroup").removeClass('d-none');
$("#districtGroup").addClass('d-none');
}
});
$('input[type=checkbox][id=autocheck]').change(function () {
if (this.checked) {
btnCheckAvailabilityCall();
}
});
$(document).ready(function () {
var url = new URL(document.location);
var params = url.searchParams;
var pincode = params.get("pincode");
if (pincode) {
$("#pincode").val(pincode);
}
var age = params.get("age");
if (age && age == 45) {
document.getElementById("age45").checked = true;
}
var autocheck = params.get("autocheck");
if (autocheck) {
document.getElementById("autocheck").checked = true;
$("#btnCheckAvailability").click();
}
var audioalert = params.get("audioalert");
if (audioalert) {
document.getElementById("audioalert").checked = true;
}
$('#pincode').keypress(function (e) {
var key = e.which;
if (key == 13) // the enter key code
{
$("#btnCheckAvailability").click();
return false;
}
});
});
$.ajax({
type: "GET",
url: "https://cdn-api.co-vin.in/api/v2/admin/location/states",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$.each(data.states, function () {
var options = "<option " + "value='" + this.state_id + "'>" + this.state_name + "";
$("#selectState").append(options);
});
$('#selectState').selectpicker('refresh');
}
});
function audioalert() {
const msg = new SpeechSynthesisUtterance("Vaccine center is now available.");
window.speechSynthesis.speak(msg);
};
</script>
</html>