-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
175 lines (169 loc) · 5.18 KB
/
Copy pathscript.js
File metadata and controls
175 lines (169 loc) · 5.18 KB
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
let countryCode = {};
let countryName = [];
const domainURL = "https://cors-anywhere.herokuapp.com/https://date.nager.at/api/v3";
window.onload = function () {
/*fetch(domainURL + "/AvailableCountries")
.then(function (response) {
if (response.status === 200) {
return response.json();
}
}).then(function (json) {
for (country of json) {
countryCode[country["name"]] = country["countryCode"];
}
});
console.log(countryCode);*/
//preset
countryCode = {
"Andorra": "AD",
"Albania": "AL",
"Argentina": "AR",
"Austria": "AT",
"Australia": "AU",
"Åland Islands": "AX",
"Bosnia and Herzegovina": "BA",
"Barbados": "BB",
"Belgium": "BE",
"Bulgaria": "BG",
"Benin": "BJ",
"Bolivia": "BO",
"Brazil": "BR",
"Bahamas": "BS",
"Botswana": "BW",
"Belarus": "BY",
"Belize": "BZ",
"Canada": "CA",
"Switzerland": "CH",
"Chile": "CL",
"China": "CN",
"Colombia": "CO",
"Costa Rica": "CR",
"Cuba": "CU",
"Cyprus": "CY",
"Czechia": "CZ",
"Germany": "DE",
"Denmark": "DK",
"Dominican Republic": "DO",
"Ecuador": "EC",
"Estonia": "EE",
"Egypt": "EG",
"Spain": "ES",
"Finland": "FI",
"Faroe Islands": "FO",
"France": "FR",
"Gabon": "GA",
"United Kingdom": "GB",
"Grenada": "GD",
"Guernsey": "GG",
"Gibraltar": "GI",
"Greenland": "GL",
"Gambia": "GM",
"Greece": "GR",
"Guatemala": "GT",
"Guyana": "GY",
"Honduras": "HN",
"Croatia": "HR",
"Haiti": "HT",
"Hungary": "HU",
"Indonesia": "ID",
"Ireland": "IE",
"Isle of Man": "IM",
"Iceland": "IS",
"Italy": "IT",
"Jersey": "JE",
"Jamaica": "JM",
"Japan": "JP",
"South Korea": "KR",
"Liechtenstein": "LI",
"Lesotho": "LS",
"Lithuania": "LT",
"Luxembourg": "LU",
"Latvia": "LV",
"Morocco": "MA",
"Monaco": "MC",
"Moldova": "MD",
"Montenegro": "ME",
"Madagascar": "MG",
"North Macedonia": "MK",
"Mongolia": "MN",
"Montserrat": "MS",
"Malta": "MT",
"Mexico": "MX",
"Mozambique": "MZ",
"Namibia": "NA",
"Niger": "NE",
"Nigeria": "NG",
"Nicaragua": "NI",
"Netherlands": "NL",
"Norway": "NO",
"New Zealand": "NZ",
"Panama": "PA",
"Peru": "PE",
"Papua New Guinea": "PG",
"Poland": "PL",
"Puerto Rico": "PR",
"Portugal": "PT",
"Paraguay": "PY",
"Romania": "RO",
"Serbia": "RS",
"Russia": "RU",
"Sweden": "SE",
"Singapore": "SG",
"Slovenia": "SI",
"Svalbard and Jan Mayen": "SJ",
"Slovakia": "SK",
"San Marino": "SM",
"Suriname": "SR",
"El Salvador": "SV",
"Tunisia": "TN",
"Turkey": "TR",
"Ukraine": "UA",
"United States": "US",
"Uruguay": "UY",
"Vatican City": "VA",
"Venezuela": "VE",
"Vietnam": "VN",
"South Africa": "ZA",
"Zimbabwe": "ZW"
};
};
document.getElementById("countrySubmit").addEventListener("click", function (event) {
event.preventDefault();
let country = document.getElementById("countryInput").value;
let value = countryCode[country];
let year = document.getElementById("yearInput").value;
if (year === "") year = new Date().getFullYear();
const countryURL = domainURL + "/PublicHolidays/" + year + "/" + value;
const tableHeaders = ["Date", "Local Name", "Name", "is Global", "Type"];
fetch(countryURL)
.then(function (response) {
if (response.status === 200) {
return response.json();
}
else{
throw new Error(response.status);
}
})
.then(function (json) {
console.log(json)
document.getElementById("holidayHead").innerHTML = 'Public Holidays in ' + country + ' (' + year + ')';
let result = "<tr>";
for (head of tableHeaders) {
result += "<th>" + head + "</th>";
}
result += "</tr>"
for (element of json) {
result += "<tr>";
result += "<td>" + element.date + "</td>";
result += "<td>" + element.localName + "</td>";
result += "<td>" + element.name + "</td>";
result += "<td>" + (element.global ? "Yes" : "No") + "</td>";
result += "<td>" + element.types + "</td>";
result += "</tr>";
}
document.getElementById("holidayResults").innerHTML = result;
}).catch(function (error) {
document.getElementById("holidayResults").innerHTML = "";
document.getElementById("holidayHead").innerHTML = "Failed to get the response! Code: " + error;
});
});