forked from Dezenix/frontend-html-css-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallJavaScript.js
232 lines (201 loc) · 7.64 KB
/
allJavaScript.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
window.onload = function() {
var page = window.location.href;
//Mega Functions:
//flip() - Runs all the newCoin.html functions
// newflip() - flips the coin
// setFace()- Changes the coin face
//clearStorage() - Runs settings.html funcrtions
// removeAllStorage() - Clears all local storage
//getFace() - Runs all coinFaces.html Functions
// setCoinStorage() - Sets local storage coin value
// removeCoinStorage() - Removes local coin storage value
//Authenticity() - runs all Authenticity.html code
// document.getElementById("coinBody").addEventListener("load", everything());
// document.getElementById("settingsBody").addEventListener("load", everything());
// document.getElementById("facesBody").addEventListener("load", everything());
// document.getElementById("authenticityBody").addEventListener("load", everything());
if (page.includes("newCoin.html")) {
console.log("flip()");
flip();
} else if (page.includes("settings.html")) {
console.log("clearStorage()");
clearStorage();
} else if (page.includes("coinFaces.html")) {
console.log("getFace()");
getFace();
} else if (page.includes("Authenticity.html")) {
console.log("auth()");
Authenticity();
}
function flip() {
document.getElementById("button").addEventListener("click", newflip);
console.log("hello");
function newflip() {
if (localStorage.getItem("headsChecked") == "true") {
console.log("Heads");
var element = document.getElementById("newCoin");
element.classList.remove("Heads", "Tails");
setTimeout(function() {
element.classList.toggle("Heads", true);
}, 100);
} else if (localStorage.getItem("tailsChecked") == "true") {
console.log("Tails");
var element = document.getElementById("newCoin");
element.classList.remove("Heads", "Tails");
setTimeout(function() {
element.classList.toggle("Tails", true);
}, 100);
} else {
console.log("fair");
var coinResult = Math.floor(Math.random() * 2);
var element = document.getElementById("newCoin");
element.classList.remove("Heads", "Tails");
setTimeout(function() {
if (coinResult == 0) {
element.classList.toggle("Heads", true);
} else {
element.classList.toggle("Tails", true);
}
}, 100)
}
document.getElementById("newCoin").addEventListener("webkitAnimationStart", () => {
document.getElementById("result").innerHTML = (". . .");
});
document.getElementById("newCoin").addEventListener("webkitAnimationEnd", () => {
document.getElementById("result").innerHTML = element.className;
});
}
//Change Coin Face Script
var i = 0;
console.log("past var");
console.log(i);
if (document.getElementById("coinBody")) {
console.log("alive");
} else {
console.log("not");
}
if (document.getElementById("coinBody")) {
console.log("started");
while (i <= 1) {
console.log("inside");
if (localStorage.getItem("coinHeads") !== null && localStorage.getItem("coinTails") !== null) {
document.getElementById("heads").src = localStorage.getItem("coinHeads");
document.getElementById("tails").src = localStorage.getItem("coinTails");
console.log("works");
i++;
} else {
console.log("Doesnt work");
i++;
}
console.log("ended");
}
};
}
//Reset All Button Script
// } else if (page.includes("settings.html")){
function clearStorage() {
document.getElementById("restore").addEventListener("click", removeAllStorage);
function removeAllStorage() {
localStorage.clear();
console.log("cleared local storage");
localStorage.setItem("fair", "true");
}
}
//Change Coin Face Script
// } else if (page.includes("coinFaces.html")){
function getFace() {
var coin;
document.getElementById("pound").addEventListener("click", () => {
coin = "pound";
console.log(coin);
setCoinStorage();
});
document.getElementById("twoFace").addEventListener("click", () => {
coin = "twoface";
console.log(coin);
setCoinStorage();
});
function setCoinStorage() {
localStorage.setItem("coinHeads", "pictures/" + coin + "-heads.png");
localStorage.setItem("coinTails", "pictures/" + coin + "-tails.png");
console.log(coin);
console.log(localStorage.getItem("coinHeads"))
}
document.getElementById("restore").addEventListener("click", removeCoinStorage);
function removeCoinStorage() {
localStorage.clear("coinHeads", "coinTails");
console.log("cleared local storage");
}
}
//Authenticity settings
// } else if (page.includes("Authenticity.html")){
function Authenticity() {
var input = document.getElementById("wrapper");
var alwaysHeads = document.getElementById("alwaysHeads");
var alwaysTails = document.getElementById("alwaysTails");
var fair = document.getElementById("fair");
if (localStorage.getItem("headsChecked") == "" && localStorage.getItem("tailsChecked") == "") {
localStorage.setItem("fair", "true");
fair.checked = localStorage.getItem("fair");
}
//sets the "always heads" checkbox to checked if it should be
alwaysHeads.checked = localStorage.getItem("headsChecked");
//checks if the checkbox is true, if yes sets a localstorage item "headsChecked" to true,
//if not, sets it to nothing
if (alwaysHeads.checked == true) {
localStorage.setItem("headsChecked", "true");
alwaysHeads.checked = localStorage.getItem("headsChecked");
} else {
localStorage.setItem("headsChecked", "");
}
//whenever any of the boxes are clicked, check if alwaysheads is checked or not.
wrapper.addEventListener("click", () => {
if (alwaysHeads.checked == true) {
localStorage.setItem("headsChecked", "true");
alwaysHeads.checked = localStorage.getItem("headsChecked");
} else {
localStorage.setItem("headsChecked", "");
}
});
//same as above, but with tails
alwaysTails.checked = localStorage.getItem("tailsChecked");
if (alwaysTails.checked == true) {
localStorage.setItem("tailsChecked", "true");
alwaysTails.checked = localStorage.getItem("tailsChecked");
} else {
localStorage.setItem("tailsChecked", "");
}
wrapper.addEventListener("click", () => {
if (alwaysTails.checked == true) {
localStorage.setItem("tailsChecked", "true");
alwaysTails.checked = localStorage.getItem("tailsChecked");
} else {
localStorage.setItem("tailsChecked", "");
}
});
console.log(localStorage.getItem("headsChecked"));
console.log(localStorage.getItem("tailsChecked"));
fair.checked = localStorage.getItem("fair");
if (fair.checked == true) {
localStorage.setItem("fair", "true");
fair.checked = localStorage.getItem("fair");
} else {
localStorage.setItem("fair", "");
}
wrapper.addEventListener("click", () => {
if (fair.checked == true) {
localStorage.setItem("fair", "true");
fair.checked = localStorage.getItem("fair");
} else {
localStorage.setItem("fair", "");
}
});
document.getElementById("restore").addEventListener("click", removeStorage);
function removeStorage() {
localStorage.clear("alwaysHeads", "alwaysTails", "fair");
console.log("cleared local storage");
localStorage.setItem("fair", "true");
fair.checked = localStorage.getItem("fair");
}
}
}