forked from HENRYMARTIN5/Clarity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClarityWorkshop.js
188 lines (148 loc) · 6.05 KB
/
ClarityWorkshop.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
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);
if (urlParams.has('page')) {
var page = urlParams.get('page');
} else {
var page = 1;
}
request.open('GET', 'https://clarityworkshop.n3rdl0rd.repl.co/getpage/' + page.toString(), 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>Featured</p>
<div class="w3-row-padding">
<div class="w3-third w3-container w3-margin-bottom">
<div class="w3-container level w3-hover-opacity" style= "cursor: pointer;" onclick="loadLevelById(36);">
<p><b>Official Clarity Tutorial</b></p>
<p>By <i><a href="user.html?user=N3rdL0rd">N3rdL0rd</a></i>, the creator of Clarity</p>
</div>
</div>
<div class="w3-third w3-container w3-margin-bottom">
<div class="w3-container level w3-hover-opacity" style= "cursor: pointer;" onclick="loadLevelById(122);">
<p><b>S.S.S.S (Single Screen Suffering Squared)</b></p>
<p>By <i><a href="user.html?user=@TdubMorris">@TdubMorris</a></i>, the co-creator of Clarity</p>
</div>
</div>
<br></br>
</div>
<p>Other Levels</p>
</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">
<div class="button-62" role="button" style= "cursor: pointer;" id="back" onclick="loadPage(` + (parseInt(page) - 1).toString() + `);">
<p><</p>
</div>
<div class="button-62" role="button" style= "cursor: pointer;" id="fwd" onclick="loadPage(` + (parseInt(page) + 1).toString() + `);">
<p>Next Page ></p>
</div>
</div>
</center>`
if (parseInt(page) === 1){
document.getElementById("back").style.display = "none";
}
if (lvlJson.length === 0){
document.getElementById("fwd").style.display = "none";
}
}
}
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 signin(){
Swal.fire({
title: 'Login to Clarity',
html: `<input type="text" id="login" class="swal2-input" placeholder="Username">
<input type="password" id="password" class="swal2-input" placeholder="Password"><br><a href="account.html">No account? Sign up instead!</a>`,
confirmButtonText: 'Login',
focusConfirm: true,
preConfirm: () => {
const login = Swal.getPopup().querySelector('#login').value
const password = Swal.getPopup().querySelector('#password').value
if (!login || !password) {
Swal.showValidationMessage(`Please enter login and password`)
}
return { login: login, password: password }
}
}).then((result) => {
var res = httpGet("https://clarityworkshop.n3rdl0rd.repl.co/login/"+encodeURIComponent(result.value.login)+"/"+encodeURIComponent(result.value.password));
if(res == "ok"){
localStorage.setItem('user', result.value.login);
window.location.reload();
} else {
Swal.fire({
type: 'error',
title: 'Oops...',
text: 'Incorrect login or password!'
})
}
})
}
function signout(){
localStorage.setItem("user", null);
document.getElementById("signinbutton").innerText = "Sign In";
document.getElementById("signinbutton").onclick = signin;
window.location.href=window.location.href;
}
function signedin(){
return localStorage.getItem("user");
}
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();
}
}