-
Notifications
You must be signed in to change notification settings - Fork 0
/
frontend.js
998 lines (827 loc) · 24.5 KB
/
frontend.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
//vue things
//<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
//install instructions: https://vuejs.org/v2/guide/installation.html
//let FuzzySet = require(['node_modules/fuzzyset/dist/fuzzyset.js']);
let user = "you are not logged in";
let helloMsg = `Hello, ${user}`
let sets = ["Set 1", "Set 2"];
let currentSetName = "";
let currentWords = ["word1", "word2", "word3"];
let currentDefs = ["def1", "def2", "def3"];
let currentIndex = 0;
let currentWord = "word";
let currentDef = "definition";
let globalCorrect = false;
let globalCorrectFuzzy = false;
let globalIncorrect = false;
let globalUploadSuccess = false;
let loggedIn = false;
let flashcardActive = false;
let writeActive = false;
let spellActive = false;
let resp;
const Demo = {
data() {
return {
show: true
}
},
// mounted() {
// setInterval(() => {
// this.show = !this.show;
// }, 1000)
// }
}
Vue.createApp(Demo).mount('#demo')
const Counter = {
data() {
return {
counter: 0
}
},
mounted() {
setInterval(() => {
this.counter++
}, 1000)
}
}
Vue.createApp(Counter).mount('#counter')
const Title = {
data() {
return {
title: helloMsg,
}
},
mounted() {
setInterval(() => {
this.title = `Hello, ${user}`;
}, 100)
}
}
Vue.createApp(Title).mount('#title')
const MakeAcct = {
data() {
return {
show: true,
}
},
mounted() {
setInterval(() => {
this.show = !loggedIn;
//console.log(this.show);
}, 100)
}
}
Vue.createApp(MakeAcct).mount('#makeacct_div')
const Login = {
data() {
return {
show: true,
}
},
mounted() {
setInterval(() => {
this.show = !loggedIn;
//console.log(this.show);
}, 100)
}
}
Vue.createApp(Login).mount('#login_div')
const Logout = {
data() {
return {
show: false,
}
},
mounted() {
setInterval(() => {
this.show = loggedIn;
}, 100)
}
}
Vue.createApp(Logout).mount('#logout_div');
const CloseGame = {
data() {
return {
show: false,
}
},
mounted() {
setInterval(() => {
if (flashcardActive || writeActive || spellActive) {
this.show = true;
} else {
this.show = false;
} }, 100)
}
}
Vue.createApp(CloseGame).mount('#close_game_div');
// const Sets = {
// data() {
// return {
// show: false,
// }
// },
// mounted() {
// setInterval(() => {
// this.show = loggedIn;
// }, 100)
// }
// }
// Vue.createApp(Sets).mount('#sets');
// const FileRead = {
// data() {
// return {
// show: true,
// }
// }
// }
// Vue.createApp(FileRead).mount('#fileRead_div')
let Flashcards = {
data: () => ({
show: false,
showSide: true,
side1:"word",
side2:"definition"
}),
methods:{
changeCard(word,def) {
// console.log("changeCard called w", word, def);
this.side1=word;
this.side2=def;
}
},
mounted() {
setInterval(() => {
this.side1 = currentWord;
this.side2 = currentDef;
this.show = flashcardActive;
}, 100)
}
}
Vue.createApp(Flashcards).mount('#flashcards_div')
let Write = {
data: () => ({
show: false,
word:"word",
definition:"definition",
correct:false,
correctfuzzy:false,
incorrect:false
}),
methods:{
changeCard(word,def) {
// console.log("changeCard called w", word, def);
this.word=word;
this.definition=def;
}
},
mounted() {
setInterval(() => {
this.word = currentWord;
this.definition = currentDef;
this.correct = globalCorrect;
this.correctfuzzy = globalCorrectFuzzy;
this.incorrect = globalIncorrect;
this.show = writeActive;
}, 100)
}
}
Vue.createApp(Write).mount('#write_div');
let Spell = {
data: () => ({
show: false,
word:"word",
definition:"definition",
correct:false,
correctfuzzy:false,
incorrect:false
}),
methods:{
changeCard(word,def) {
// console.log("changeCard called w", word, def);
this.word=word;
this.definition=def;
}
},
mounted() {
setInterval(() => {
this.word = currentWord;
this.definition = currentDef;
this.correct = globalCorrect;
this.correctfuzzy = globalCorrectFuzzy;
this.incorrect = globalIncorrect;
this.show = spellActive;
}, 100)
}
}
Vue.createApp(Spell).mount('#spell_div')
//Vue is data driven so dynamically add sets
let getsets = async function () {
// clear out any existing child elements
document.getElementById("sets").innerHTML = "";
let e = document.createElement("h3");
e.innerHTML = "Your Sets:";
document.getElementById("sets").appendChild(e);
//TODO get all sets with privacy set to "false" or set to true and your username
let a;
const pathToPhpFile = 'http://ec2-54-157-162-187.compute-1.amazonaws.com/quizlet/getsets.php'
var obj;
a = JSON.parse(await $.ajax({
type: 'POST',
// make sure you respect the same origin policy with this url:
// http://en.wikipedia.org/wiki/Same_origin_policy
data: {
username: user,
},
url: pathToPhpFile,
success: function (msg) {
console.log(msg);
},
failure: function (msg) {
//alert('failedreq')
obj = { 'status': 'requestfailed' };
}
}));
let starred;
const pathToPhpFile2 = 'http://ec2-54-157-162-187.compute-1.amazonaws.com/quizlet/mongodb.php'
var obj;
b = JSON.parse(await $.ajax({
type: 'POST',
// make sure you respect the same origin policy with this url:
// http://en.wikipedia.org/wiki/Same_origin_policy
url: pathToPhpFile2,
data: {
username: user,
},
success: function (msg) {
console.log(msg);
},
failure: function (msg) {
//alert('failedreq')
console.log(msg);
}
}));
// console.log(a);
// console.log(b);
//adds name of set and buttons
//add your sets first
//b[""]
a["user"].forEach((s, index) => {
let d = document.createElement("p");
let mostmissed = [];
s["cards"].forEach((card) => {
// console.log("card obj", card);
// console.log("comparing", card[2], " & ", card[3])
if (card[2]<card[3]){
mostmissed.push(card[0]+" ("+(card[2]-card[3])+")");
}
});
// console.log("most missed cards", mostmissed);
//Check for Starred Sets
let favflag = false;
b["starredsets"].forEach(g => {
// console.log( s["name"] + " === " + g);
if( s["name"] === g ){
d.innerHTML += "<strong>" + s["name"] + "</strong> ";
favflag = true;
}
})
if(!favflag){
d.innerHTML += s["name"]+" ";
}
let starButton;
if (!favflag){
starButton = document.createElement('button');
starButton.innerHTML += "Star Me!";
d.appendChild(starButton);
}
let flashcardButton = document.createElement('button');
flashcardButton.innerHTML += "Flashcards";
d.appendChild(flashcardButton);
let writeButton = document.createElement('button');
writeButton.innerHTML += "Writing";
d.appendChild(writeButton);
let spellButton = document.createElement('button');
spellButton.innerHTML += "Spell";
d.appendChild(spellButton);
if (mostmissed.length>0){
let string = " Often Missed: | ";
mostmissed.forEach(m =>{
string+= m+" | ";
});
// string+= "("+mostmissed.length+")";
let missed = document.createTextNode(string);
d.appendChild(missed);
}
document.getElementById("sets").appendChild(d);
if (!favflag){
starButton.addEventListener("click", function () { starSet(s) }, false);
}
flashcardButton.addEventListener("click", function () { runFlashcard(s) }, false);
writeButton.addEventListener("click", function () { runWriting(s) }, false);
spellButton.addEventListener("click", function () { runSpell(s) }, false);
});
let e2 = document.createElement("h3");
e2.innerHTML = "Popular Sets:";
document.getElementById("sets").appendChild(e2);
//Add public sets
a["public"].forEach((s, index) => {
let d = document.createElement("p");
//Save for starred sets
//d.innerHTML += "<strong>" + s["name"] + "</strong>";
//Check for Starred Sets
let favflag = false;
b["starredsets"].forEach(g => {
console.log( s["name"] + " === " + g);
if( s["name"] === g ){
d.innerHTML += "<strong>" + s["name"] + "</strong> ";
favflag = true;
}
})
if (!favflag){
d.innerHTML += s["name"]+" ";
}
let starButton;
if (!favflag){
starButton = document.createElement('button');
starButton.innerHTML += "Star Me!";
d.appendChild(starButton);
}
let flashcardButton = document.createElement('button');
flashcardButton.innerHTML += "Flashcards";
d.appendChild(flashcardButton);
let writeButton = document.createElement('button');
writeButton.innerHTML += "Writing";
d.appendChild(writeButton);
let spellButton = document.createElement('button');
spellButton.innerHTML += "Spell";
d.appendChild(spellButton);
document.getElementById("sets").appendChild(d);
if (!favflag){
starButton.addEventListener("click", function () { starSet(s) }, false);
}
flashcardButton.addEventListener("click", function () { runFlashcard(s) }, false);
writeButton.addEventListener("click", function () { runWriting(s) }, false);
spellButton.addEventListener("click", function () { runSpell(s) }, false);
});
}
let runFlashcard = async function (setObject) {
console.log("running flashcard with", setObject);
console.log("setobj", setObject);
//TODO set setName as currentWords and currentDefs
currentSetName = setObject["name"];
sets = [];
currentWords = [];
currentDefs = [];
setObject["cards"].forEach(s => {
currentWords[currentWords.length] = s[0];
currentDefs[currentDefs.length] = s[1];
})
currentIndex = -1;
flashcardNext();
flashcardActive = true;
writeActive = false;
spellActive = false;
//don't look at this i know it's bad
//It's ok Lane I still love you - Evin
//https://stackoverflow.com/questions/16623852/how-to-pause-javascript-code-execution-for-2-seconds
try {
document.getElementById("flashcardNext").removeEventListener("click", flashcardNext, false);
document.getElementById("flashcardBack").removeEventListener("click", flashcardBack, false);
document.getElementById("close_game").removeEventListener("click", closeGame , false);
} catch (e){}
setTimeout(function(){
document.getElementById("flashcardNext").addEventListener("click", flashcardNext, false);
document.getElementById("flashcardBack").addEventListener("click", flashcardBack, false);
document.getElementById("close_game").addEventListener("click", closeGame , false);
}, 100);
}
let runWriting = async function (setObject) {
console.log("running flashcard with", setObject);
console.log("setobj", setObject);
currentSetName = setObject["name"];
sets = [];
currentWords = [];
currentDefs = [];
setObject["cards"].forEach(s => {
currentWords[currentWords.length] = s[0];
currentDefs[currentDefs.length] = s[1];
})
currentIndex = -1;
writeNext();
flashcardActive = false;
writeActive = true;
spellActive = false;
try {
document.getElementById("writeNext").removeEventListener("click", writeNext, false);
document.getElementById("write_submit").removeEventListener("click", checkWrite , false);
document.getElementById("close_game").removeEventListener("click", closeGame , false);
} catch (e) {}
setTimeout(function(){
document.getElementById("writeNext").addEventListener("click", writeNext , false);
document.getElementById("write_submit").addEventListener("click", checkWrite , false);
document.getElementById("close_game").addEventListener("click", closeGame , false);
}, 100);
}
let runSpell = function (setObject) {
console.log("running spell with", setObject);
console.log("setobj", setObject);
currentSetName = setObject["name"];
sets = [];
currentWords = [];
currentDefs = [];
setObject["cards"].forEach(s => {
currentWords[currentWords.length] = s[0];
currentDefs[currentDefs.length] = s[1];
})
currentIndex = -1;
spellNext();
writeActive = false;
flashcardActive = false;
spellActive = true;
//don't look at this i know it's bad
//It's ok Lane I still love you - Evin
//https://stackoverflow.com/questions/16623852/how-to-pause-javascript-code-execution-for-2-seconds
try {
document.getElementById("spellNext").removeEventListener("click", spellNext, false);
document.getElementById("spell_submit").removeEventListener("click", checkSpell , false);
document.getElementById("spell_audio").removeEventListener("click", spellAudio , false);
document.getElementById("close_game").removeEventListener("click", closeGame , false);
} catch (e){}
setTimeout(function(){
document.getElementById("spellNext").addEventListener("click", spellNext, false);
document.getElementById("spell_submit").addEventListener("click", checkSpell , false);
document.getElementById("spell_audio").addEventListener("click", spellAudio , false);
document.getElementById("close_game").addEventListener("click", closeGame , false);
}, 100);
}
let spellAudio = function () {
var msg = new SpeechSynthesisUtterance();
var voices = window.speechSynthesis.getVoices();
msg.voice = voices[10];
msg.volume = 1; // From 0 to 1
msg.rate = 1; // From 0.1 to 10
msg.pitch = 2; // From 0 to 2
msg.text = currentDef;
msg.lang = 'en';
speechSynthesis.speak(msg);
console.log("playing audio of", currentDef);
}
let spellNext = function () {
console.log("next");
currentIndex++;
if (currentIndex==currentWords.length){
currentIndex=0;
}
currentWord = currentWords[currentIndex];
currentDef = currentDefs[currentIndex];
if (document.getElementById('spell_word')!= null){
document.getElementById('spell_word').value = '';
}
globalCorrect = false;
globalIncorrect = false;
globalCorrectFuzzy = false;
Spell.methods.changeCard(currentWords[currentIndex], currentDefs[currentIndex]);
}
let checkSpell = function () {
let attempt = document.getElementById("spell_word").value;
console.log(attempt);
let fuzzy = new FuzzySet(currentWords);
let fuzzyresp = fuzzy.get(attempt);
let fuzzyattempt = '';
if (fuzzyresp!=null){
if (fuzzyresp.length>0){
if (fuzzyresp[0][0] > .7){
fuzzyattempt = fuzzyresp[0][1];
}
}
}
console.log("attempt:", attempt);
console.log("fuzzy attempt:", fuzzyattempt);
console.log("true answer: ", currentWord);
if (attempt === currentWord){
globalCorrect = true;
updateWrite(true, currentIndex);
} else if (fuzzyattempt === currentWord) {
globalCorrectFuzzy = true;
updateWrite(true, currentIndex);
} else {
globalIncorrect = true;
updateWrite(false, currentIndex);
}
}
let flashcardNext = function () {
console.log("next");
currentIndex++;
if (currentIndex==currentWords.length){
currentIndex=0;
}
currentWord = currentWords[currentIndex];
currentDef = currentDefs[currentIndex];
Flashcards.methods.changeCard(currentWords[currentIndex], currentDefs[currentIndex]);
}
let flashcardBack = function (){
console.log("back");
currentIndex--;
if (currentIndex==-1){
currentIndex=currentWords.length-1;
}
currentWord = currentWords[currentIndex];
currentDef = currentDefs[currentIndex];
Flashcards.methods.changeCard(currentWords[currentIndex], currentDefs[currentIndex]);
}
let checkWrite = function() {
let attempt = document.getElementById("write_word").value;
console.log(attempt);
let fuzzy = new FuzzySet(currentWords);
let fuzzyresp = fuzzy.get(attempt);
let fuzzyattempt = '';
if (fuzzyresp!=null){
if (fuzzyresp.length>0){
if (fuzzyresp[0][0] > .7){
fuzzyattempt = fuzzyresp[0][1];
}
}
}
console.log("attempt:", attempt);
console.log("fuzzy attempt:", fuzzyattempt);
console.log("true answer: ", currentWord);
if (attempt === currentWord){
globalCorrect = true;
updateWrite(true, currentIndex);
} else if (fuzzyattempt === currentWord) {
globalCorrectFuzzy = true;
updateWrite(true, currentIndex);
} else {
globalIncorrect = true;
updateWrite(false, currentIndex);
}
}
let writeNext = function(){
console.log("next");
currentIndex++;
if (currentIndex==currentWords.length){
currentIndex=0;
}
currentWord = currentWords[currentIndex];
currentDef = currentDefs[currentIndex];
if (document.getElementById('write_word')!= null){
document.getElementById('write_word').value = '';
}
globalCorrect = false;
globalIncorrect = false;
globalCorrectFuzzy = false;
Write.methods.changeCard(currentWords[currentIndex], currentDefs[currentIndex]);
}
let updateWrite = async function (correct, index) {
console.log("updating!", correct, index);
const pathToPhpFile = 'http://ec2-54-157-162-187.compute-1.amazonaws.com/quizlet/updateset.php'
$.ajax({
type: "POST",
data: {
name: currentSetName,
index : index,
correct: correct
},
url: pathToPhpFile,
success: function(msg){
console.log("successfully sent to php",msg);
},
});
}
let makeacct = async function () {
let a;
const pathToPhpFile = 'http://ec2-54-157-162-187.compute-1.amazonaws.com/quizlet/createaccount.php'
a = await $.ajax({
type: 'POST',
// make sure you respect the same origin policy with this url:
// http://en.wikipedia.org/wiki/Same_origin_policy
url: pathToPhpFile,
data: {
'user': document.getElementById('cusername').value,
'password': document.getElementById('cpassword').value,
'email': document.getElementById('cemail').value,
},
success: function (msg) {
console.log(msg);
alert("Check your email for the verify code!");
},
failure: function (msg) {
//alert('failedreq')
console.log(msg)
}
});
// let verify = document.createElement("p");
// //verify Email here
// document.getElementById("makeacct_div").appendChild(d);
}
//FileReader code updated to Vue3 from https://www.raymondcamden.com/2019/05/21/reading-client-side-files-for-validation-with-vuejs
const fileRead = {
data() {
return {
show: true,
text:'',
lines: [],
success: false
}
},
methods:{
selectedFile(event) {
console.log('selected a file');
//console.log(this.$refs.myFile.files[0]);
let file = this.$refs.myFile.files[0];
if(!file || file.type !== 'text/plain') return;
let reader = new FileReader();
reader.readAsText(file, "UTF-8");
reader.onload = evt => {
this.text = evt.target.result;
this.lines=this.text.split("\n");
// console.log("text: ",this.text);
// console.log("lines: ",this.lines);
uploadSet(this.lines)
}
reader.onerror = evt => {
console.error(evt);
}
}
},
mounted() {
setInterval(() => {
if (flashcardActive || writeActive || spellActive || !loggedIn) {
this.show = false;
} else {
this.show = true;
}
this.success = globalUploadSuccess;
}, 100)
}
}
Vue.createApp(fileRead).mount('#fileRead_div')
let uploadSet = async function (c) {
console.log(c);
let name = c[0];
let privacy = c[1];
let contents = c.slice(2);
if (!contents[contents.length-1] || contents[contents.length-1] == "\r"){
contents.pop();
}
console.log(contents);
const pathToPhpFile = 'http://ec2-54-157-162-187.compute-1.amazonaws.com/quizlet/uploadset.php'
let resp = $.ajax({
type: "POST",
data: {
name: name,
privacy: privacy,
contents : contents,
user: user
},
url: pathToPhpFile,
success: function(msg){
console.log("successfully sent to php",msg);
if (msg.includes("Inserted 1")){
globalUploadSuccess = true;
}
},
});
getsets();
}
let starSet = async function(set) {
console.log("want to star", set["name"]);
const pathToPhpFile = 'http://ec2-54-157-162-187.compute-1.amazonaws.com/quizlet/starset.php'
$.ajax({
type: 'POST',
url: pathToPhpFile,
data: {
user: user,
name: set["name"],
},
url: pathToPhpFile,
success: function(msg){
console.log("successfully sent to php",msg);
}
});
getsets();
}
let query = async function () {
/*
//let localToken = await getCSRFtoken();
//https://classes.engineering.wustl.edu/cse330/content/weather_json.php
let a;
const pathToPhpFile = 'http://ec2-54-157-162-187.compute-1.amazonaws.com/quizlet/login.php'
var obj;
return $.ajax({
type: 'POST',
// make sure you respect the same origin policy with this url:
// http://en.wikipedia.org/wiki/Same_origin_policy
url: pathToPhpFile,
data: {
'token': 'hewwo'
},
success: function (msg) {
document.getElementById("ajaxtest").innerHTML = msg;
},
failure: function (msg) {
alert('failedreq')
}
});
const pathToPhpFile = 'http://ec2-54-157-162-187.compute-1.amazonaws.com/quizlet/mongodb.php';
const data = { x: 'hi', y: 'hello' };
fetch(pathToPhpFile, {
method: "POST",
body: JSON.stringify(data)
})
.then(res => resp = res)
.then(response => document.getElementById("ajaxtest").innerHTML = response)
.catch(error => console.error('Error:',error))
*/
let a;
const pathToPhpFile = 'http://ec2-54-157-162-187.compute-1.amazonaws.com/quizlet/mongodb.php'
var obj;
return $.ajax({
type: 'POST',
// make sure you respect the same origin policy with this url:
// http://en.wikipedia.org/wiki/Same_origin_policy
url: pathToPhpFile,
success: function (msg) {
console.log(msg);
},
failure: function (msg) {
//alert('failedreq')
obj = { 'status': 'requestfailed' };
}
});
}
let logout = async function(){
closeGame();
globalUploadSuccess = false;
user = "you are not logged in";
loggedIn = false;
console.log("logged in?", loggedIn);
try{
setTimeout(function(){
if(document.getElementById("logout") != null){
document.getElementById("logout").addEventListener("click", async function () { await logout() }, false);
}
}, 300);
}
catch(e){
console.log(e);
}
document.getElementById("sets").innerHTML = "";
setTimeout(function(){
document.getElementById("login").addEventListener("click", async function () { await login() }, false);
document.getElementById("makeacct").addEventListener("click", async function () { await makeacct(); }, false);
}, 300);
}
//add token test
let login = async function(){
let a;
const pathToPhpFile = 'http://ec2-54-157-162-187.compute-1.amazonaws.com/quizlet/login.php'
var obj;
return $.ajax({
type: 'POST',
// make sure you respect the same origin policy with this url:
// http://en.wikipedia.org/wiki/Same_origin_policy
url: pathToPhpFile,
data: {
'username': document.getElementById('lusername').value,
'password': document.getElementById('lpassword').value,
},
success: function (msg) {
console.log(msg);
let res = JSON.parse(msg);
if(res["status"] == true){
user = document.getElementById('lusername').value;
helloMsg = `Hello, ${user}`;
loggedIn = true;
console.log("logged in?", loggedIn);
setTimeout(function(){
document.getElementById("logout").addEventListener("click", async function () { await logout() }, false);
}, 200);
setTimeout(function(){
getsets();
}, 200);
}
else{
alert("Failed to log in\n (Hint: Make sure your email is verified)");
}
},
failure: function (msg) {
//alert('failedreq')
obj = { 'status': 'requestfailed' };
}
});
}
let closeGame = function () {
console.log("closing");
flashcardActive = false;
writeActive = false;
spellActive = false;
getsets();
}
//document.getElementById("loadsets").addEventListener("click", async function () { }, false);
document.getElementById("makeacct").addEventListener("click", async function () { await makeacct(); }, false);
//document.getElementById("queery").addEventListener("click", async function () { resp = await query(); document.getElementById("ajaxtest").innerHTML = resp; }, false);
document.getElementById("uploadset").addEventListener("click", async function () { await uploadSet() }, false);
document.getElementById("login").addEventListener("click", async function () { await login() }, false);