-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.html
263 lines (230 loc) · 9.89 KB
/
game.html
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
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Peeling The Onion</title>
<link rel="shortcut icon" href="/logo.png">
<style type="text/css">
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 15% auto; /* 15% from the top and centered */
padding: 20px;
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
}
/* The Close Button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
</style>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<div class="container">
<div class="title">
<div>
<span id="title-text">Qual notícia é verdadeira?</span>
</div>
<div>
<span id="correct-text">Acertos:</span><span id="score"></span><span> / </span><span id="turns-text">Rodadas:</span><span id="total"></span>
</div>
</div>
<div id="left" class="option left-panel" onclick="clickLeft()">
<div class="text"></div>
</div>
<div id="right" class="option right-panel" onclick="clickRight()">
<div class="text"></div>
</div>
</div>
<div id="modal" class="modal">
<div class="modal-content">
<p id="modal-text"></p>
<a target="_blank" rel="noopener noreferrer" id="modal-fake-news" href="">Notícia falsa no Sensacionalista</a><br>
<a target="_blank" rel="noopener noreferrer" id="modal-true-news" href="">Notícia real no Surrealista</a>
<span class="close">Próxima</span>
</div>
</div>
</body>
<script>
let rand = 0;
let score = 0;
let total = 0;
var modal = document.getElementById("modal");
var span = document.getElementsByClassName("close")[0];
function generateRandomInteger(min, max) {
return Math.floor(min + Math.random()*(max + 1 - min))
}
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
let urlVars = getUrlVars();
if (urlVars["lang"] === "en") {
document.getElementById("modal-fake-news").innerHTML = "Untrue news from The Onion";
document.getElementById("modal-true-news").innerHTML = "Real news from r/nottheonion";
document.getElementsByClassName("close")[0].innerHTML = "Next";
document.getElementById("title-text").innerHTML = "Which news is real?";
document.getElementById("correct-text").innerHTML = "Corrects:";
document.getElementById("turns-text").innerHTML = "Turn:";
}
var getJSON = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "json";
xhr.onload = function() {
var status = xhr.status;
if (status === 200) {
callback(null, xhr.response);
} else {
callback(status, xhr.response);
}
};
xhr.send();
};
let truthJSON = null;
let fakeJSON = null;
getJSON(urlVars["lang"] === "br" ? "surrealista.json" : "https://www.reddit.com/r/nottheonion/.json",
function(err, data) {
if (err !== null) {
alert("Something went wrong: " + err);
}
else {
truthJSON = data;
if (fakeJSON != null) {
nextPair();
}
}
});
getJSON(urlVars["lang"] === "br" ? "sensacionalista.json" : "https://www.reddit.com/r/theonion/.json",
function(err, data) {
if (err !== null) {
alert("Something went wrong: " + err);
}
else {
fakeJSON = data;
if (truthJSON != null) {
nextPair();
}
}
});
var clickLeft = function() {
if (rand === 0) {
score += 1;
document.getElementById("modal-text").innerHTML = urlVars["lang"] === "br" ?
"Acertou! Essa é verdade mesmo!" :
"That's right! This is the correct one!";
}
else {
document.getElementById("modal-text").innerHTML = urlVars["lang"] === "br" ?
"Olha a cobraa! É mentira!" :
"Nope, this is one is an onion.";
}
total += 1;
modal.style.display = "block";
}
var clickRight = function() {
if (rand === 1) {
score += 1;
document.getElementById("modal-text").innerHTML = urlVars["lang"] === "br" ?
"Acertou! Essa é verdade mesmo!" :
"That's right! This is the correct one!";
}
else {
document.getElementById("modal-text").innerHTML = urlVars["lang"] === "br" ?
"Olha a cobraa! É mentira!" :
"Nope, this is one is an onion.";
}
total += 1;
modal.style.display = "block";
}
function nextPair() {
document.getElementById("score").innerHTML = score.toString();
document.getElementById("total").innerHTML = total.toString();
rand = generateRandomInteger(0, 1);
//Truth
let random = urlVars["lang"] === "br" ? generateRandomInteger(0, truthJSON.length-1) : generateRandomInteger(0, truthJSON.data.dist-1);
if (urlVars["lang"] === "br") {
document.getElementById("modal-true-news").href = truthJSON[random].link;
}
else {
document.getElementById("modal-true-news").href = truthJSON.data.children[random].data.url;
}
if (rand === 0) {
if (urlVars["lang"] === "br") {
document.getElementById("left").firstElementChild.innerHTML = truthJSON[random].title.toLowerCase();
}
else {
document.getElementById("left").firstElementChild.innerHTML = truthJSON.data.children[random].data.title.toLowerCase();
}
}
else {
if (urlVars["lang"] === "br") {
document.getElementById("right").firstElementChild.innerHTML = truthJSON[random].title.toLowerCase();
}
else {
document.getElementById("right").firstElementChild.innerHTML = truthJSON.data.children[random].data.title.toLowerCase();
}
}
//Lie
random = urlVars["lang"] === "br" ? generateRandomInteger(0, fakeJSON.length-1) : generateRandomInteger(0, fakeJSON.data.dist-1);
if (urlVars["lang"] === "br") {
document.getElementById("modal-fake-news").href = fakeJSON[random].link;
}
else {
document.getElementById("modal-fake-news").href = fakeJSON.data.children[random].data.url;
}
if (rand === 0) {
if (urlVars["lang"] === "br") {
document.getElementById("right").firstElementChild.innerHTML = fakeJSON[random].title.toLowerCase();
}
else {
document.getElementById("right").firstElementChild.innerHTML = fakeJSON.data.children[random].data.title.toLowerCase();
}
}
else {
if (urlVars["lang"] === "br") {
document.getElementById("left").firstElementChild.innerHTML = fakeJSON[random].title.toLowerCase();
}
else {
document.getElementById("left").firstElementChild.innerHTML = fakeJSON.data.children[random].data.title.toLowerCase();
}
}
}
span.onclick = function() {
modal.style.display = "none";
nextPair();
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
nextPair();
}
}
</script>
</html>