forked from Bashamega/bark-coding.desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
282 lines (254 loc) · 10 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/* Some common scripts created in javascript to work the website, and make it interactive. */
let toevaluate = ["/src/scripts/injector.js"];
toevaluate.forEach(path => {
fetch(path)
.then(data => data.text())
.then(data => {
(async () => {
eval(data);
})(); //run in a seprate thread so it doesnt block this scripts execution
});
});
let newsBox = "<a href='https://bark.dumorando.com'>bark.dumorando.com</a> is a new domain of Bark Coding!.<br><br>Thanks to dumorando, Bark accounts now work!<br><br>Try out the new <a href='https://bark.dumorando.com/editor/cool'>advanced editor</a>!";
let baseUrl = window.location.origin;
let commitsLength = 150;
let mobile = window.navigator.userAgent.toLowerCase().includes("mobi");
// if your a dev and u know what ur doing use tampermonkey to set showHoldOn to false automatically
let showHoldOn = true;
/*
if (document.URL.includes('bark-coding.vercel.app')) {
window.location.href = "https://bark.dumorando.com" + document.URL.replaceAll(window.location.origin, "")
}
*/
if (showHoldOn) {
console.log("%cHold on!", "font-size:36pt; color: dodgerblue;");
console.log("Pasting anything in the console can get your account stolen.");
}
document.body.innerHTML += "<button onclick='scrollToTop()' class='buttonFrBx' id='topBtn' disabled>Top</button>";
// i copied this
function randomstring() {
let length = 8,
charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
retVal = "";
for (let i = 0, n = charset.length; i < length; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * n));
}
return retVal;
}
if (!localStorage.getItem("secret")) {
localStorage.setItem("secret", randomstring());
}
// footer
// @deprecated use <!-- inject:footer --> instead.
/*
if (document.url != "baseUrl") {
let footer;
footer = '<footer><p style="color: #777;">Looks like you\'ve reached the bottom.</p><p>';
footer += '<a href="'+baseUrl+'">Home</a> '; // Home
footer += '<a href="/editor/">Editor</a> '; // Editor
footer += '<a href="https://github.com/mariocraft987/bark.github.io/">Github</a> '; // Github
footer += '<br/><br/><a href="https://github.com/mariocraft987/bark-coding/wiki">Wiki</a> '; // Wiki
footer += '<a href="https://discord.gg/hXmHw7H9BF">Discord</a> '; // Discord
footer += '</p></footer>'
document.body.innerHTML += footer;
}
*/
if (localStorage.getItem("myBarkUsername")) {
if (localStorage.getItem("barktoken")) {
//verify to see if the username matches the token.
fetch(`https://api.bark.dumorando.com/api/v2/currentUser?token=${localStorage.getItem("barktoken")}`)
.then(data => data.json())
.then(data => {
if (data.error === 'Reauthenticate') {
localStorage.removeItem("myBarkUsername");
localStorage.removeItem("barktoken");
location.reload();
} else {
if (data.username !== localStorage.getItem("myBarkUsername")) {
localStorage.removeItem("myBarkUsername");
localStorage.removeItem("barktoken");
location.reload();
}
}
});
} else {
localStorage.removeItem("myBarkUsername");
location.reload();
}
}
if (new Date().getMonth() === 3 && new Date().getDate() === 1) {
document.getElementById("flip-it-afd-btn").addEventListener("click", function () {
document.body.classList.toggle("afd-upside-down");
localStorage.setItem("flip-it-afd", document.body.classList.contains("afd-upside-down"));
})
window.addEventListener("load", function () {
if (localStorage.getItem("flip-it-afd") == "true") {
this.document.body.classList.add("afd-upside-down");
}
})
}
function whatsNew() {
if (document.URL == baseUrl + "/") {
document.getElementById("boxChanger").innerHTML = "<h2>Whats New?</h2><p>" + newsBox + "</p>";
}
}
function randomTxt() {
//geeksforgeeks.org for the random text generator.
if (document.URL == baseUrl + "/explore") {
fetch(window.location.origin +'/src/scripts/tips.json')
.then(res => res.json()).then(data => {
obj = data;
})
.then(() => {
wrd = obj[parseInt(Math.random() * obj.length)]
document.getElementById("randomWord").innerHTML = wrd;
});
}
}
function jobRegister() {
let job = document.querySelector('input[name=job]:checked').value;
let username = document.getElementById('github-username').value;
document.getElementById('page').innerHTML = '<br/><h2>You have selected a Job to ' + job + '</h2><p>We have to run a few tests to see your actually <em>' + username + '</em></p><br/><br/><p>Please comment "Job Register 4067"';
document.getElementById('page').innerHTML += ' on <a class="link" href="https://github.com/Mariocraft987/bark.github.io/commit/5644df6ebc5aa7ea7b611141a265ff7c17712c5e">this commit</a>.</p>'
}
/* @mnsderp for the data saving scripts */
// Function to toggle dark mode
function toggleDarkMode() {
const body = document.body;
body.classList.toggle('dark-mode');
// Save dark mode state to local storage
const isDarkMode = body.classList.contains('dark-mode');
localStorage.setItem('darkMode', isDarkMode);
}
// Function to initialize dark mode based on local storage
function initializeDarkMode() {
const isDarkMode = localStorage.getItem('darkMode') === 'true';
const body = document.body;
if (isDarkMode) {
body.classList.add('dark-mode');
} else {
body.classList.remove('dark-mode');
}
}
// Initialize dark mode when the page loads
window.addEventListener('load', initializeDarkMode);
whatsNew();
const theme = localStorage.getItem('theme');
if (theme) {
if (theme.startsWith('#')) {
const style = document.createElement('style');
document.head.append(style);
const link = document.createElement('link');
link.rel = "stylesheet";
link.href = window.location.origin + `/src/themes/bluedodger.css`;
document.head.append(link);
} else if (theme != "bluedodger") {
const link = document.createElement('link');
link.rel = "stylesheet";
link.href = window.location.origin +`/src/themes/${theme}.css`;
document.head.append(link);
} else {
const link = document.createElement('link');
link.rel = "stylesheet";
link.href = window.location.origin+`/src/themes/bluedodger.css`;
document.head.append(link);
}
} else {
const link = document.createElement('link');
link.rel = "stylesheet";
link.href = window.location.origin + `/src/themes/bluedodger.css`;
document.head.append(link);
}
let mybutton = document.getElementById("topBtn");
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.disabled = false;
} else {
mybutton.disabled = true;
}
}
// When the user clicks on the button, scroll to the top of the document
function scrollToTop() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}
let x, i, j, l, ll, selElmnt, a, b, c;
/*look for any elements with the class "custom-select":*/
x = document.getElementsByClassName("custom-select");
l = x.length;
for (i = 0; i < l; i++) {
selElmnt = x[i].getElementsByTagName("select")[0];
ll = selElmnt.length;
/*for each element, create a new DIV that will act as the selected item:*/
a = document.createElement("DIV");
a.setAttribute("class", "select-selected");
a.innerHTML = selElmnt.options[selElmnt.selectedIndex].innerHTML;
x[i].appendChild(a);
/*for each element, create a new DIV that will contain the option list:*/
b = document.createElement("DIV");
b.setAttribute("class", "select-items select-hide");
for (j = 1; j < ll; j++) {
/*for each option in the original select element,
create a new DIV that will act as an option item:*/
c = document.createElement("DIV");
c.innerHTML = selElmnt.options[j].innerHTML;
c.addEventListener("click", function(e) {
/*when an item is clicked, update the original select box,
and the selected item:*/
let y, i, k, s, h, sl, yl;
s = this.parentNode.parentNode.getElementsByTagName("select")[0];
sl = s.length;
h = this.parentNode.previousSibling;
for (i = 0; i < sl; i++) {
if (s.options[i].innerHTML == this.innerHTML) {
s.selectedIndex = i;
h.innerHTML = this.innerHTML;
y = this.parentNode.getElementsByClassName("same-as-selected");
yl = y.length;
for (k = 0; k < yl; k++) {
y[k].removeAttribute("class");
}
this.setAttribute("class", "same-as-selected");
break;
}
}
h.click();
});
b.appendChild(c);
}
x[i].appendChild(b);
a.addEventListener("click", function(e) {
/*when the select box is clicked, close any other select boxes,
and open/close the current select box:*/
e.stopPropagation();
closeAllSelect(this);
this.nextSibling.classList.toggle("select-hide");
this.classList.toggle("select-arrow-active");
});
}
function closeAllSelect(elmnt) {
/*a function that will close all select boxes in the document,
except the current select box:*/
let x, y, i, xl, yl, arrNo = [];
x = document.getElementsByClassName("select-items");
y = document.getElementsByClassName("select-selected");
xl = x.length;
yl = y.length;
for (i = 0; i < yl; i++) {
if (elmnt == y[i]) {
arrNo.push(i)
} else {
y[i].classList.remove("select-arrow-active");
}
}
for (i = 0; i < xl; i++) {
if (arrNo.indexOf(i)) {
x[i].classList.add("select-hide");
}
}
}
/*if the user clicks anywhere outside the select box,
then close all select boxes:*/
document.addEventListener("click", closeAllSelect);