-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteve.js
131 lines (110 loc) · 4.52 KB
/
steve.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
var firebaseConfig = {
apiKey: "AIzaSyB2kMCF_wglD3NPBDjSl6phkYrorRI1LgE",
authDomain: "minecraft-world-community.firebaseapp.com",
databaseURL: "https://minecraft-world-community-default-rtdb.firebaseio.com",
projectId: "minecraft-world-community",
storageBucket: "minecraft-world-community.appspot.com",
messagingSenderId: "79164899563",
appId: "1:79164899563:web:36388146fef46073c63eae"
};
firebase.initializeApp(firebaseConfig);
//things
var user = localStorage.getItem("user");
var userPass = localStorage.getItem("pass");
function loadUser() {
if (user == undefined) {
window.location = "index.html";
}
document.getElementById("userName").innerHTML = user;
}
returnBox = new Infobox("return to rooms", "Return to Minecraft Rooms page?", "exitdoor.webp", "Return", "roomPage()", "cancelReturn()", "white", "lime");
function returnPage() {
returnBox.open();
}
function cancelReturn() {
returnBox.close();
}
function roomPage() {
window.location = "MinecraftRooms.html";
}
var searchUser = "";
function getData() {
firebase.database().ref("/users/").on('value', function (snapshot) {
document.getElementById("output").innerHTML = "";
snapshot.forEach(function (childSnapshot) {
childKey = childSnapshot.key; childData = childSnapshot.val();
userNames = childKey;
userData = childData;
if (userNames != user) {
if (searchUser == "" || searchUser == userNames) {
image = userData["userImg"];
followers = userData["followers"];
if (image == "creeper") {
imgTag = "<img src='UserCreeper.png' class='userImg'>";
} else if (image == "enderman") {
imgTag = "<img src='UserEnderman.png' class='userImg'>";
} else if (image == "zombie") {
imgTag = "<img src='UserZombie.png' class='userImg'>";
} else if (image == "steve") {
imgTag = "<img src='UserSteve.png' class='userImg'>";
} else if (image == "pig") {
imgTag = "<img src='UserPig.png' class='userImg'>";
}
label = "<label class='userLabel'>" + userNames + "</label>";
followDiv = "<button class='follow' onclick='follow(this.title,"+followers+")' title='" + userNames + "'>Follow User | " + followers + "</button>";
row = "<div class='roomName' id=" + userNames + ">" + imgTag + label + followDiv + "</div><br><br>";
document.getElementById("output").innerHTML += row;
}
}
});
});
}
function getUserData() {
firebase.database().ref("/users/"+user+"/userImg").on('value', data => {
UserImage = data.val();
if (UserImage == "creeper") {
document.getElementById("userPicture").src = "UserCreeper.png";
} else if (UserImage == "enderman") {
document.getElementById("userPicture").src = "UserEnderman.png";
} else if (UserImage == "zombie") {
document.getElementById("userPicture").src = "UserZombie.png";
} else if (UserImage == "steve") {
document.getElementById("userPicture").src = "UserSteve.png";
} else if (UserImage == "pig") {
document.getElementById("userPicture").src = "UserPig.png";
}
})
firebase.database().ref("/users/"+user+"/followers").on('value', data => {
followNumber = data.val();
document.getElementById("userFollow").innerHTML = "Following: "+followNumber;
})
firebase.database().ref("/users/" + user + "/password").on('value', data => {
password = data.val();
if(password != userPass){
window.location = "index.html";
}
})
}
getData();
getUserData();
function onTheme() {
localStorage.setItem("theme", "dark");
}
function offTheme() {
localStorage.setItem("theme", "default");
}
function searching() {
searchUser = document.getElementById("searchBox").value;
getData();
}
function follow(userId,followNumber){
updateFollow = Number(followNumber) + 1;
firebase.database().ref("users/"+userId).update({
followers: updateFollow
});
}
function selectPicture(pic){
firebase.database().ref("users/"+user).update({
userImg: pic
});
}