forked from HENRYMARTIN5/Clarity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClarityTop.js
107 lines (81 loc) · 3.4 KB
/
ClarityTop.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
function splitIntoChunk(inputArray, perChunk) {
var result = inputArray.reduce((resultArray, item, index) => {
const chunkIndex = Math.floor(index / perChunk)
if (!resultArray[chunkIndex]) {
resultArray[chunkIndex] = [] // start a new chunk
}
resultArray[chunkIndex].push(item)
return resultArray
}, [])
return result
}
window.onload = function () {
var request = new XMLHttpRequest();
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
request.open('GET', 'https://clarityworkshop.n3rdl0rd.repl.co/toplvls/', false); // `false` makes the request synchronous
request.send(null);
if (request.status === 200) {
var currentLvls = request.responseText;
var lvlJson = JSON.parse(currentLvls);
console.log(lvlJson);
var splitLvlJson = splitIntoChunk(lvlJson, 3);
console.log(splitLvlJson);
document.getElementById("container").innerHTML = "";
const container = document.getElementById("container");
container.innerHTML = `
<div id="pinnedcontainer">
<p>Top Levels</p>
<br></br>
</div>`
// <div class="w3-third w3-container w3-margin-bottom">
// <div class="w3-container level w3-hover-opacity" style= "cursor: pointer;" onclick="alert('haha u thought')">
// <p><b>Campaign Mode</b></p>
// <p>The official story campaign for Clarity</p>
// </div>
// </div>
splitLvlJson.forEach(levels => {
console.log(levels);
const container = document.getElementById("container");
var newRow = document.createElement("div");
newRow.class = "w3-row-padding";
levels.forEach(level => {
console.log(level);
var newelem = `
<div class="w3-third w3-container w3-margin-bottom w3-hover-opacity" style= "cursor: pointer;" onclick="loadLevelById({levelId});">
<div class="w3-container level">
<p><b>{level}</b></p>
<p>By <a href="user.html?user={author}">{author}</a> - Likes: {likes}</p>
</div>
</div>`.replace("{level}", level["name"]).replace("{author}", level["author"]).replace("{author}", level["author"]).replace("{levelId}", level["id"]).replace("{likes}", level["likes"]);
newRow.innerHTML = newRow.innerHTML + newelem;
})
newRow.innerHTML = newRow.innerHTML + "</br>";
container.appendChild(newRow);
})
// append pagination buttons (back, fwd, etc)
container.innerHTML = container.innerHTML + `
<center>
<div id="pagination" class="w3-row-padding">
<a class="button-62" role="button" style= "cursor: pointer;" id="back" href="https://discountdevs.github.io/Clarity-Legacy/workshop.html?page=1">
<p>< Back</p>
</a>
</div>
</center>`
}
}
function loadPage(page) {
window.location.href = "https://discountdevs.github.io/Clarity-Legacy/workshop.html?page=" + (page).toString();
}
function loadLevelById(id) {
window.location.href = "https://discountdevs.github.io/Clarity-Legacy/level.html?id=" + (id).toString();
}
function mylvls(){
// get the signed in user
var user = signedin();
if(user){
window.location.href="https://discountdevs.github.io/Clarity-Legacy/user.html?user="+encodeURIComponent(user);
} else {
signin();
}
}