forked from AdamDIOM/MELONsquad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·237 lines (209 loc) · 6.76 KB
/
index.js
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
async function MELONsquad(){
navBar();
console.log(window.location.href);
if(window.location.href.includes("%23")){
hash = window.location.href.indexOf("%");
window.location.href = window.location.href.substring(0,hash) + '#' + window.location.href.substring(hash+3);
}
//setting pos to a number so high it won't be reached
pos = 500
pos = window.location.href.indexOf("#")
pos2 = window.location.href.lastIndexOf("#");
/*for(c in window.location.href){
if(window.location.href[c] == '#' && c < pos){
console.log(c);
pos = c;
break;
}
}*/
console.log(pos);
if(pos == pos2) {
ending = window.location.href.substring(pos);
ChoosePage(ending);
}
else{
ending = window.location.href.substring(pos,pos2);
await ChoosePage(ending);
anchor = window.location.href.substring(pos2 + 1).toLowerCase();
console.log("second: " + anchor);
scrollSmoothTo(anchor);
}
console.log("ending: " + ending);
}
function scrollSmoothTo(elementId) {
var element = document.getElementById(elementId);
element.scrollIntoView({
block: 'start',
behavior: 'smooth'
});
}
async function ChoosePage(ending){
switch(ending.toLowerCase()){
case "#about":
About()
break;
case "#team":
await TeamMembers();
break;
case "#squad":
await TeamMembers();
break;
case "#gang":
await TeamMembers();
break;
case "#history":
await History();
break;
case "#art":
await Art();
break;
case "#recipes":
await Recipes();
break;
case "#join":
JoinSquad();
break;
case "#join-us":
JoinSquad();
break;
default:
MELON();
break;
}
}
async function navBar(){
navList = document.getElementById('list');
//console.log("list");
const response = await fetch("JSON/navbar.json")
.then(response => response.json());
json = response;
//console.log(json);
for(link in json){
//console.log(link)
navList.innerHTML += `<a href="#${json[link].link}"><li onclick="${json[link].onclick}">${json[link].text}</li></a>`
}
}
function MELON(){
section.innerHTML = `
<h1 id="sectionHeading">MELONsquad</h1>
<h1>🍉🦈</h1>
<img src="Assets/BLAHAJ.gif" id="blahajpic">
`
}
function About(){
section.innerHTML = "<h1 id=\"sectionHeading\">About - Coming soon...</h1>"
}
async function TeamMembers(){
section.innerHTML = "<h1 id=\"sectionHeading\">The Squad</h1>"
team = await AddImageBoxes("Team", "team");
section.innerHTML += team;
}
async function History(){
section.innerHTML = `
<h1 id="sectionHeading">History</h1>
<h2>It's time to make history by winning Local Hack Day: Share together!</h2>
<h2>Find below some of the historical hackathon prizes our MELONsquad members have won... this is why we will be the best squad at LHD: Share!</h2>
`
hHistory = await HackathonHistory();
section.innerHTML += hHistory;
}
async function Art(){
section.innerHTML = "<h1 id=\"sectionHeading\">Art</h1>"
art = await AddImageBoxes("Art", "art", true);
section.innerHTML += art;
}
async function Recipes(){
section.innerHTML = "<h1 id=\"sectionHeading\">Recipes</h1>"
const response = await fetch("JSON/recipes.json")
.then(response => response.json());
json = response
console.log(json.mlb.name);
recipeString = "<ol>"
for(s in json.mlb.steps){
console.log(json.mlb.steps[s]);
recipeString += "<li>"
recipeString += json.mlb.steps[s];
recipeString += "</li>"
}
recipeString += "</ol>"
section.innerHTML += recipeString;
}
function JoinSquad(){
section.innerHTML = `
<h1 id="sectionHeading">Join us!</h1>
<div>
<h2>Instructions</h2>
<ol>
<li>Visit <a href="https://discord.mlh.io" target="_blank">discord.mlh.io</a>
<li>Click Sign in with Discord</li>
<li>Log in</li>
<li>Click Edit Profile</li>
<li>Scroll to Guild Membership</li>
<li>Select guild BLAHAJGang</li>
<li>Visit the BLAHAJgang Discord Channel</li>
<li>Add the melon and shark emoji to your nickname (🍉🦈)</li>
<li>Optional - ask to be added to the <a href="#squad" target="_blank">website</a></li>
</ol>
</div>
`;
}
async function AddImageBoxes(imageDirectory, jsonFile, link = false){
const response = await fetch("JSON/" + jsonFile + '.json')
.then(response => response.json());
json = response
team = "";
for(user in json){
if(!Array.isArray(json[user].image)){
imageurl = json[user].image;
} else {
//console.log(json[user].image.length);
imgNum = Math.floor(Math.random() * (json[user].image.length));
console.log(imgNum);
imageurl = json[user].image[imgNum];
}
team += AddImageBox(imageDirectory + "/" + imageurl, json[user].name, json[user].caption, user, link);
}
return team;
}
function AddImageBox(imageSrc, title, caption, user, link){
box = "";
if(link){
box += `<a id="noformat" href="Assets/${imageSrc}" target="_blank">`
}
box += `
<div class="wideBox" id="${user}">
<div id="boxImg">
<img src="Assets/${imageSrc}">
</div>
<p id="title">${title}</p>
<p id="caption">${caption}</p>
</div>
`
if(link){
box += `</a>`
}
return box;
}
async function HackathonHistory(){
const response = await fetch("JSON/wins.json")
.then(response => response.json());
json = response;
historystring = "";
for(hacker in json){
//console.log(json[hacker]);
//console.log(json[hacker].hackathons[0].name);
historystring += `
<div id="historyOuter">
<h2>${json[hacker].name}</h2>
`
for(hackathon in json[hacker].hackathons){
historystring += `<a href="${json[hacker].hackathons[hackathon].link}" target="_blank" id="noformat">`;
historystring += AddImageBox("Hackathons/" + json[hacker].hackathons[hackathon].name + ".png", json[hacker].hackathons[hackathon].name, json[hacker].hackathons[hackathon].prize);
historystring += `</a>`;
}
historystring += `</div>`;
//console.log(historystring);
}
//console.log(historystring);
return historystring;
}