-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
206 lines (154 loc) · 5.18 KB
/
index.html
File metadata and controls
206 lines (154 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
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
<!-- your html file: -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<title>Function scope example</title>
</head>
<body>
<h1>
Animal Crossing: New Horizons in Season Fish
</h1>
<body>
This is a site that shows which fish are currently in season for both hemispheres. Not very good with styling so sorry for the plain site.
</body>
<div>
<div id="nhTable">
<h2> Northern Hemisphere</h2>
</div>
<div id="shTable">
<h2> Southern Hemisphere</h2>
</div>
</div>
<header>
</header>
<section>
</section>
<script>
const months = ['Jan','Feb','Mar','Apr','May',
'June','July','Aug','Sept','Oct','Nov','Dec'];
function getAvailableFish(fish_json, currentMonth){
let available_fish = [];
available_fish.push(Object.keys(fish_json));
let size = Object.keys(fish_json['seasonality']).length;
for (i = 0; i < size; i++){
if (fish_json['seasonality'][i] == 'All year'){
available_fish.push(
[fish_json['fish'][i],
fish_json['seasonality'][i],
fish_json['location'][i],
fish_json['time'][i],
fish_json['price'][i]]
);
}else {
let all_month_range = fish_json['seasonality'][i].split(" - ")
let month_range1 = [];
let month_range2= [];
if (all_month_range.length <= 2){
index1 = months.indexOf(all_month_range[0]);
index2 =months.indexOf(all_month_range[1]);
month_range1 = generateRange(index1, index2);
}else if (all_month_range.length == 4){
index1 = months.indexOf(all_month_range[0]);
index2 =months.indexOf(all_month_range[1]);
index3 = months.indexOf(all_month_range[2]);
index4 =months.indexOf(all_month_range[3]);
month_range1 = generateRange(index1, index2);
month_range2 = generateRange(index3, index4);
let rawSeasonality = fish_json['seasonality'][i];
let rawSeasonalitySplit = rawSeasonality.split(" - ");;
let newSeasonalitySplit = `${rawSeasonalitySplit[0]} - ${rawSeasonalitySplit[1]}, ${rawSeasonalitySplit[2]}-${rawSeasonalitySplit[3]}`;
fish_json['seasonality'][i] = newSeasonalitySplit;
}
if(month_range1.includes(currentMonth) || month_range2.includes(currentMonth)){
available_fish.push(
[fish_json['fish'][i],
fish_json['seasonality'][i],
fish_json['location'][i],
fish_json['time'][i],
fish_json['price'][i]]
);
}
}
}
return available_fish;
}
function jsonToTable(customers, div) {
//Create a HTML Table element.
var table = document.createElement("TABLE");
table.border = "1";
//Get the count of columns.
var columnCount = customers[0].length;
//Add the header row.
var row = table.insertRow(-1);
for (var i = 0; i < columnCount; i++) {
var headerCell = document.createElement("TH");
headerCell.innerHTML = customers[0][i];
row.appendChild(headerCell);
}
//Add the data rows.
for (var i = 1; i < customers.length; i++) {
row = table.insertRow(-1);
for (var j = 0; j < columnCount; j++) {
var cell = row.insertCell(-1);
cell.innerHTML = customers[i][j];
}
}
var dvTable = document.getElementById(div);
dvTable.appendChild(table);
// var dv2Table = document.getElementById("dv2Table");
// dv2Table.innerHTML = "";
// dv2Table.appendChild(table);
}
function getMonthRange(month1, month2){
months_index_range = []
monthCounter = month1;
months_index_range.push(month1);
while (monthCounter -12 != month2){
monthCounter++;
if (monthCounter >= 12){
months_index_range.push(monthCounter-12);
}else{
months_index_range.push(monthCounter);
}
}
return months_index_range;
}
function range(start, end) {
return Array(end - start + 1).fill().map((_, idx) => start + idx)
}
function generateRange(index1, index2){
let month_range;
if (index1 > index2){
month_range = getMonthRange(index1, index2);
} else{
month_range = range(index1, index2)
}
return month_range
}
let date = new Date();
let currentMonth = date.getMonth();
let requestURL = "https://raw.githubusercontent.com/AmanRiat1/anch_collection/master/nh_fish.json";
let request = new XMLHttpRequest();
request.open('GET', requestURL);
request.responseType = 'json';
request.send();
request.onload = function() {
const nh_fish_json = request.response;
let nh_fish_array = getAvailableFish(nh_fish_json, currentMonth);
jsonToTable(nh_fish_array, "nhTable");
}
let requestURL2 = "https://raw.githubusercontent.com/AmanRiat1/anch_collection/master/sh_fish.json";
let request2 = new XMLHttpRequest();
request2.open('GET', requestURL2);
request2.responseType = 'json';
request2.send();
request2.onload = function() {
const sh_fish_json = request2.response;
let sh_fish_array = getAvailableFish(sh_fish_json, currentMonth);
jsonToTable(sh_fish_array, "shTable");
}
</script>
</body>
</html>