-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.js
242 lines (207 loc) · 8.18 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
/* 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
});
});
if (document.URL == "https://bark.dumorando.com/profile/" || document.URL == "https://bark.dumorando.com/profile") {
window.location.href = "https://bark.dumorando.com/users";
}
let newsBox = `
Bark is getting a web application version as well as a new theme along with it!
`;
let baseUrl = window.location.origin;
let commitsLength = 150;
let mobile = window.navigator.userAgent.toLowerCase().includes("mobi");
let isFirefox = window.navigator.userAgent.toLowerCase().includes("firefox")
let showHoldOn = true;
// conditionals
if (document.URL.includes('bark-coding.vercel.app') || document.URL.includes('mariocraft987.github.io/bark-coding')) {
localStorage.barktoken = null;
window.location.href = "https://bark.dumorando.com" + document.URL.replaceAll(window.location.origin, "");
}
if (showHoldOn) {
// this exists because yeah
shout = "";
for (i = 0; i < 3; i++) {
shout = shout + "!";
console.log("%cHold on%s", "font-weight: bold; font-size: 50pt; color: red;", shout);
}
console.log("If anyone asks you to paste something in here, Don't do it!! \nThey might be trying to steal, or ban your account! \nIf you are trying to paste something in here, then make sure its from a trusted source!");
}
document.body.innerHTML += "<button onclick='scrollToTop()' class='buttonFrBx' id='topBtn' disabled>Top</button>";
function randomstring(length = 8) {
const RandomCharacter = () => String.fromCharCode(Math.random() * (126 - 32) + 32);
return Array.from({ length }, RandomCharacter).join("");
}
if (!localStorage.getItem("secret")) {
localStorage.setItem("secret", randomstring());
}
function CheckLoggedIn() {
if (localStorage.getItem("barktoken") === null) {
localStorage.removeItem("myBarkUsername");
return;
}
// Quick note, probably shouldn't send the token in the search string, use POST instead.
fetch(`https://api.bark.dumorando.com/api/v2/currentUser?token=${localStorage.getItem("barktoken")}`)
.then(data => data.json())
.then(data => {
const ReauthNeeded = data.error === 'Reauthenticate';
if (!ReauthNeeded) {
localStorage.setItem("myBarkUsername", data.username)
return;
}
localStorage.removeItem("myBarkUsername");
localStorage.removeItem("barktoken");
location.reload();
});
}
CheckLoggedIn();
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 (location.pathname !== "/")
return;
document.getElementById("boxChanger").innerHTML = "<h2>Whats New?</h2><p>" + newsBox + "</p>";
}
function randomTxt() {
if (location.pathname !== "/explore")
return;
fetch("/src/json/tips.json")
.then(res => res.json())
.then(data => {
var tip = data[parseInt(Math.random() * data.length)];
document.getElementById("randomWord").innerHTML = tip;
});
}
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" on <a class="link" href="https://github.com/Mariocraft987/bark.github.io/commit/5644df6e">this commit</a>.</p>`;
}
/* @mnsderp for the data saving scripts */
function toggleDarkMode() {
const body = document.body;
body.classList.toggle('dark-mode');
const isDarkMode = body.classList.contains('dark-mode');
localStorage.setItem('darkMode', isDarkMode);
}
function initializeDarkMode() {
const isDarkMode = localStorage.getItem('darkMode') === 'true';
const body = document.body;
if (!isDarkMode)
return;
body.classList.add('dark-mode');
}
initializeDarkMode();
whatsNew();
InitTheme()
function InitTheme() {
if (localStorage.theme == "bluedodger" && localStorage.navcolor != "nocolor") {
document.getElementById("navbar_color").value = localStorage.navcolor;
document.getElementById("navbar").style.background = localStorage.navcolor;
} else {
const theme = localStorage.getItem('theme') ?? "bluedodger";
if (theme.startsWith('#')) {
const style = document.createElement('style');
document.head.append(style);
const link = document.createElement('link');
link.rel = "stylesheet";
link.href = `/src/themes/bluedodger.css`;
document.head.append(link);
return;
}
const link = document.createElement('link');
link.rel = "stylesheet";
link.href = `/src/themes/${theme}.css`;
document.head.append(link);
return;
}
}
let mybutton = document.getElementById("topBtn");
window.onscroll = scrollFunction;
function scrollFunction() {
var Down20PX = document.documentElement.scrollTop > 20 || document.body.scrollTop > 20;
mybutton.disabled = !Down20PX;
}
function scrollToTop() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // everything else
}
let CustomSelect = document.getElementsByClassName("custom-select");
for (let i = 0; i < CustomSelect.length; i++) {
let selectElement = CustomSelect[i].querySelector("select");
let SelectedItem = document.createElement("div");
SelectedItem.setAttribute("class", "select-selected");
SelectedItem.innerHTML = selectElement.options[selectElement.selectedIndex].innerHTML;
CustomSelect[i].appendChild(a);
let OptionList = document.createElement("div");
OptionList.setAttribute("class", "select-items select-hide");
for (let j = 1; j < selectElement.length; j++) {
let option = document.createElement("div");
option.innerHTML = selElmnt.options[j].innerHTML;
option.addEventListener("click", function(e) {
let select = this.parentNode.parentNode.getElementsByTagName("select")[0];
let OptionItem = this.parentNode.previousSibling;
for (let i = 0; i < select.options.length; i++) {
if (select.options[i].innerHTML == this.innerHTML) {
select.selectedIndex = i;
OptionItem.innerHTML = this.innerHTML;
let LastSelected = this.parentNode.getElementsByClassName("same-as-selected");
for (let k = 0; k < LastSelected.length; k++) {
LastSelected[k].removeAttribute("class");
}
this.setAttribute("class", "same-as-selected");
break;
}
}
OptionItem.click();
});
OptionList.appendChild(option);
}
CustomSelect[i].appendChild(OptionList);
SelectedItem.addEventListener("click", function(e) {
e.stopPropagation();
closeAllSelect(this);
this.nextSibling.classList.toggle("select-hide");
this.classList.toggle("select-arrow-active");
});
}
function closeAllSelect(elemnt) {
let IndexesThatAreSelected = [];
let SelectItems = document.getElementsByClassName("select-items");
let SelectedItems = document.getElementsByClassName("select-selected");
for (let i = 0; i < SelectedItems.length; i++) {
if (elemnt != SelectedItems[i]) {
SelectedItems[i].classList.remove("select-arrow-active");
continue;
}
IndexesThatAreSelected.push(i);
}
for (let i = 0; i < SelectItems.length; i++) {
if (!IndexesThatAreSelected.includes(i))
continue;
SelectItems[i].classList.add("select-hide");
}
}
document.addEventListener("click", closeAllSelect);
console.log("-----------------------------------------");
console.log("All scripts were ran successfully!")