-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulation.html
195 lines (155 loc) · 5.32 KB
/
simulation.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Simulation</title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<!-- <link rel="shortcut icon" href="images/icon.png" /> -->
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
</head>
<body>
<div id="container">
<header>
<a href="summary.html"><p>Home</p></a>
</header>
<!--<h1>Dysglrepghia</h1>
<p> this is something</p>-->
<div id="content" style="text-align:center">
<br>
<br>
<p style="font-size:larger">The last person wrote:</p>
<p id="dys" style="font-size: 200%">Loading . . .</p>
<br>
<br>
<br>
<br>
<br>
<form>
<p style="font-size:smaller">What do you think they actually meant?</p>
<input type="text" id="text" autocomplete="off" placeholder="Enter your answer here" name="question">
<input type="submit" id="submit" value="submit">
</form>
</div>
</div>
<script src="https://www.gstatic.com/firebasejs/5.5.4/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.5.4/firebase-database.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyB4V0cEMBuSwR05-UvcR437IJNRVMb4TaE",
authDomain: "tbaa-103f3.firebaseapp.com",
databaseURL: "https://tbaa-103f3.firebaseio.com",
projectId: "tbaa-103f3",
storageBucket: "tbaa-103f3.appspot.com",
messagingSenderId: "503354521935"
};
firebase.initializeApp(config);
</script>
<script>
$(document).ready(function(){
// could probably make the "Loading . . ." text fade to begin with which
// would be cool.
// method to get the most recent ref ID. replace .ref('1') with .ref(refID) from this method
var wordId;
var newWordId;
var pageLoad = false;
var stringToModify;
var modifiedString = '';
var topLvlString;
var randomNumber = Math.floor((Math.random()*3)+1); // which string to look at
if (randomNumber == 1) {
topLvlString = "butter";
} else if (randomNumber == 2) {
topLvlString = "myson";
} else if (randomNumber == 3) {
topLvlString = "bear";
}
var idList = firebase.database().ref(topLvlString);
idList.once('value').then(function(snapshot) {
for (var i = 0; i < snapshot.val().wordId.length; i ++) {
wordId = i; // gets the id of the most recent addition
newWordId = i+1; // gets the new id
}
//for (var i = 0; i <= snapshot.val())
document.getElementById("submit").onclick = function() {
var stringToSubmit = document.getElementById("text").value;
firebase.database().ref(topLvlString + '/priority').set({
value: 0
});
// we're getting the string that's being entered. should probably
// check that the string length is somewhat similar to the entered length (with a 3 char margin or whatever)
firebase.database().ref(topLvlString + '/wordId/' + newWordId).set({
word: stringToSubmit
});
firebase.database().ref(topLvlString + '/priority').set({
value: 0
});
$(location).attr('href', "results.html");
return false;
};
var wordRef = firebase.database().ref(topLvlString + '/wordId/' + wordId );
console.log(topLvlString + '/wordId/' + wordId);
wordRef.once('value').then(function(snapshot) {
stringToModify = snapshot.val().word;
String.prototype.replaceAt=function(index, replacement) {
return this.substr(0, index) + replacement + this.substr(index + replacement.length);
}
var length = stringToModify.length;
for (var i = 0; i < length; i++) {
var character = stringToModify.charAt(i);
if (i % 2 == 0) {
if (character == "a") {
var random = Math.floor((Math.random()*2)+1);
if (random == 1) {
modifiedString = modifiedString + "o";
} else if (random == 2) {
modifiedString = modifiedString + "e";
}
} else if (character == "e") {
modifiedString = modifiedString + "o";
} else if (character == "h") {
modifiedString = modifiedString + "b";
} else if (character == "b") {
var random = Math.floor((Math.random()*2)+1);
if (random == 1) {
modifiedString = modifiedString + "p";
} else if (random == 2) {
modifiedString = modifiedString + "h";
}
} else if (character == "o") {
modifiedString = modifiedString + "a";
} else if (character == "w") {
modifiedString = modifiedString + "m";
} else if (character == "m") {
modifiedString = modifiedString + "w";
} else if (character == "q") {
modifiedString = modifiedString + "g";
} else if (character == "g") {
modifiedString = modifiedString + "q";
} else if (character == "t") {
modifiedString = modifiedString + "i";
} else if (character == "n") {
modifiedString = modifiedString + "u";
} else if (character == "l") {
modifiedString = modifiedString + "i";
} else if (character == "i") {
modifiedString = modifiedString + "t";
} else {
modifiedString = modifiedString + character;
}
} else {
modifiedString = modifiedString + character;
}
}
// method to actually modify the string. store it and then change 'im pickle rick' to the modified string.
if (!pageLoad) {
document.getElementById("dys").innerHTML = modifiedString;
pageLoad = true;
}
});
});
});
</script>
</body>
</html>