Skip to content

Commit 06c2ce1

Browse files
committed
made sure the website will work without analytics
1 parent 4086646 commit 06c2ce1

4 files changed

Lines changed: 155 additions & 122 deletions

File tree

public/js/account.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ function signUp() {
7070
}).then(function() {
7171
// Update successful.
7272
showNotification("Account created", 2000);
73-
firebase.analytics().logEvent("accountCreated", usr.uid);
73+
try{
74+
firebase.analytics().logEvent("accountCreated", usr.uid);
75+
}catch(e){
76+
console.log("Analytics unavailable");
77+
}
7478
$(".pageLogin .preloader").addClass('hidden');
7579
changePage('account');
7680
}).catch(function(error) {

public/js/commandline.js

Lines changed: 110 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function capitalizeFirstLetter(str) {
22
return str.charAt(0).toUpperCase() + str.slice(1);
3-
}
3+
}
44

55
let commands = {
66
title: "",
@@ -374,9 +374,13 @@ $("#commandInput textarea").keydown((e) => {
374374
}
375375
}
376376
});
377-
firebase.analytics().logEvent('usedCommandLine', {
378-
command: command
379-
});
377+
try{
378+
firebase.analytics().logEvent('usedCommandLine', {
379+
command: command
380+
});
381+
}catch(e){
382+
console.log("Analytics unavailable");
383+
}
380384
hideCommandLine();
381385
}
382386
return;
@@ -403,9 +407,13 @@ $("#commandLine input").keydown((e) => {
403407
}
404408
});
405409
if (!subgroup && !input) {
406-
firebase.analytics().logEvent('usedCommandLine', {
407-
command: command
408-
});
410+
try{
411+
firebase.analytics().logEvent('usedCommandLine', {
412+
command: command
413+
});
414+
}catch(e){
415+
console.log("Analytics unavailable");
416+
}
409417
hideCommandLine();
410418
}
411419
return;
@@ -445,7 +453,7 @@ $("#commandLine input").keydown((e) => {
445453
}
446454
});
447455
} catch (e) { }
448-
456+
449457
return false;
450458
}
451459
});
@@ -454,25 +462,25 @@ $("#commandLine input").keydown((e) => {
454462

455463
function hideCommandLine() {
456464
$("#commandLineWrapper")
457-
.stop(true, true)
458-
.css("opacity", 1)
459-
.animate(
460-
{
461-
opacity: 0
462-
},
463-
100,
464-
() => {
465-
$("#commandLineWrapper").addClass("hidden");
466-
}
465+
.stop(true, true)
466+
.css("opacity", 1)
467+
.animate(
468+
{
469+
opacity: 0
470+
},
471+
100,
472+
() => {
473+
$("#commandLineWrapper").addClass("hidden");
474+
}
467475
);
468-
focusWords();
469-
}
470-
471-
function showCommandLine() {
472-
$("#commandLine").removeClass('hidden');
473-
$("#commandInput").addClass('hidden');
474-
if ($("#commandLineWrapper").hasClass("hidden")) {
475-
$("#commandLineWrapper")
476+
focusWords();
477+
}
478+
479+
function showCommandLine() {
480+
$("#commandLine").removeClass('hidden');
481+
$("#commandInput").addClass('hidden');
482+
if ($("#commandLineWrapper").hasClass("hidden")) {
483+
$("#commandLineWrapper")
476484
.stop(true, true)
477485
.css("opacity", 0)
478486
.removeClass("hidden")
@@ -481,84 +489,85 @@ function showCommandLine() {
481489
opacity: 1
482490
},
483491
100
484-
);
485-
}
486-
$("#commandLine input").val("");
487-
updateSuggestedCommands();
488-
$("#commandLine input").focus();
489-
}
490-
491-
function showCommandInput(command, placeholder) {
492-
$("#commandLineWrapper").removeClass('hidden');
493-
$("#commandLine").addClass('hidden');
494-
$("#commandInput").removeClass('hidden');
495-
$("#commandInput textarea").attr('placeholder', placeholder);
496-
$("#commandInput textarea").val('');
497-
$("#commandInput textarea").focus();
498-
$("#commandInput textarea").attr('command', '');
499-
$("#commandInput textarea").attr('command', command);
500-
}
501-
502-
function updateSuggestedCommands() {
503-
let inputVal = $("#commandLine input").val().toLowerCase().split(" ");
504-
if (inputVal[0] == "") {
505-
$.each(currentCommands.list, (index, obj) => {
506-
obj.found = true;
507-
});
508-
} else {
509-
$.each(currentCommands.list, (index, obj) => {
510-
let foundcount = 0;
511-
$.each(inputVal, (index2, obj2) => {
512-
if (obj2 == "") return;
513-
let re = new RegExp("\\b"+obj2, "g");
514-
let res = obj.display.toLowerCase().match(re);
515-
if (res != null && res.length > 0) {
516-
foundcount++;
517-
} else {
518-
foundcount--;
519-
}
520-
});
521-
if (foundcount > 0) {
522-
obj.found = true;
492+
);
493+
}
494+
$("#commandLine input").val("");
495+
updateSuggestedCommands();
496+
$("#commandLine input").focus();
497+
}
498+
499+
function showCommandInput(command, placeholder) {
500+
$("#commandLineWrapper").removeClass('hidden');
501+
$("#commandLine").addClass('hidden');
502+
$("#commandInput").removeClass('hidden');
503+
$("#commandInput textarea").attr('placeholder', placeholder);
504+
$("#commandInput textarea").val('');
505+
$("#commandInput textarea").focus();
506+
$("#commandInput textarea").attr('command', '');
507+
$("#commandInput textarea").attr('command', command);
508+
}
509+
510+
function updateSuggestedCommands() {
511+
let inputVal = $("#commandLine input").val().toLowerCase().split(" ");
512+
if (inputVal[0] == "") {
513+
$.each(currentCommands.list, (index, obj) => {
514+
obj.found = true;
515+
});
523516
} else {
524-
obj.found = false;
517+
$.each(currentCommands.list, (index, obj) => {
518+
let foundcount = 0;
519+
$.each(inputVal, (index2, obj2) => {
520+
if (obj2 == "") return;
521+
let re = new RegExp("\\b"+obj2, "g");
522+
let res = obj.display.toLowerCase().match(re);
523+
if (res != null && res.length > 0) {
524+
foundcount++;
525+
} else {
526+
foundcount--;
527+
}
528+
});
529+
if (foundcount > 0) {
530+
obj.found = true;
531+
} else {
532+
obj.found = false;
533+
}
534+
});
525535
}
526-
});
527-
}
528-
displayFoundCommands();
529-
}
530-
531-
function displayFoundCommands() {
532-
$("#commandLine .suggestions").empty();
533-
$.each(currentCommands.list, (index, obj) => {
534-
if (obj.found) {
535-
$("#commandLine .suggestions").append(
536-
'<div class="entry" command="' + obj.id + '">' + obj.display + "</div>"
537-
);
536+
displayFoundCommands();
538537
}
539-
});
540-
if ($("#commandLine .suggestions .entry").length == 0) {
541-
$("#commandLine .separator").css({ height: 0, margin: 0 });
542-
} else {
543-
$("#commandLine .separator").css({
544-
height: "1px",
545-
"margin-bottom": ".5rem"
546-
});
547-
}
548-
let entries = $("#commandLine .suggestions .entry");
549-
if (entries.length > 0) {
550-
$(entries[0]).addClass("active");
551-
try{
538+
539+
function displayFoundCommands() {
540+
$("#commandLine .suggestions").empty();
552541
$.each(currentCommands.list, (index, obj) => {
553542
if (obj.found) {
554-
obj.hover();
555-
return false;
543+
$("#commandLine .suggestions").append(
544+
'<div class="entry" command="' + obj.id + '">' + obj.display + "</div>"
545+
);
546+
}
547+
});
548+
if ($("#commandLine .suggestions .entry").length == 0) {
549+
$("#commandLine .separator").css({ height: 0, margin: 0 });
550+
} else {
551+
$("#commandLine .separator").css({
552+
height: "1px",
553+
"margin-bottom": ".5rem"
554+
});
556555
}
557-
});
558-
}catch(e){}
559-
}
560-
$("#commandLine .listTitle").remove();
561-
// if(currentCommands.title != ''){
562-
// $("#commandLine .suggestions").before("<div class='listTitle'>"+currentCommands.title+"</div>");
563-
// }
564-
}
556+
let entries = $("#commandLine .suggestions .entry");
557+
if (entries.length > 0) {
558+
$(entries[0]).addClass("active");
559+
try{
560+
$.each(currentCommands.list, (index, obj) => {
561+
if (obj.found) {
562+
obj.hover();
563+
return false;
564+
}
565+
});
566+
}catch(e){}
567+
}
568+
$("#commandLine .listTitle").remove();
569+
// if(currentCommands.title != ''){
570+
// $("#commandLine .suggestions").before("<div class='listTitle'>"+currentCommands.title+"</div>");
571+
// }
572+
}
573+

public/js/script.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -468,21 +468,32 @@ function showResult() {
468468
showCrown();
469469
}
470470
completedEvent.uid = firebase.auth().currentUser.uid;
471-
firebase.analytics().logEvent('testCompleted', completedEvent);
471+
try{
472+
firebase.analytics().logEvent('testCompleted', completedEvent);
473+
}catch(e){
474+
console.log("Analytics unavailable");
475+
}
472476
db_testCompleted(completedEvent);
473477
dbSnapshot.unshift(completedEvent);
474478
});
475479
$("#result .loginTip").addClass('hidden');
476480
} else {
477-
firebase.analytics().logEvent('testCompletedNoLogin', completedEvent);
481+
try{
482+
firebase.analytics().logEvent('testCompletedNoLogin', completedEvent);
483+
}catch(e){
484+
console.log("Analytics unavailable");
485+
}
478486
$("#result .loginTip").removeClass('hidden');
479487

480488
// showNotification("Sign in to save your result",3000);
481489
}
482490
} else {
483491
showNotification("Test invalid", 3000);
484-
firebase.analytics().logEvent('testCompletedInvalid', completedEvent);
485-
492+
try{
493+
firebase.analytics().logEvent('testCompletedInvalid', completedEvent);
494+
}catch(e){
495+
console.log("Analytics unavailable");
496+
}
486497
}
487498

488499

@@ -671,9 +682,6 @@ function changePage(page) {
671682

672683
}
673684
}
674-
// firebase.analytics().logEvent('changedPage', {
675-
// page: page
676-
// });
677685
}
678686

679687
function changeMode(mode) {
@@ -889,10 +897,14 @@ $(document).keypress(function(event) {
889897
if (event["keyCode"] == 27) return;
890898
//start the test
891899
if (currentInput == "" && inputHistory.length == 0) {
892-
if (firebase.auth().currentUser != null) {
893-
firebase.analytics().logEvent('testStarted');
894-
} else {
895-
firebase.analytics().logEvent('testStartedNoLogin');
900+
try{
901+
if (firebase.auth().currentUser != null) {
902+
firebase.analytics().logEvent('testStarted');
903+
} else {
904+
firebase.analytics().logEvent('testStartedNoLogin');
905+
}
906+
}catch(e){
907+
console.log("Analytics unavailable");
896908
}
897909
testActive = true;
898910
stopCaretAnimation();
@@ -927,9 +939,9 @@ $(document).keypress(function(event) {
927939
accuracyStats.correct++;
928940
}
929941
currentInput += event["key"];
930-
setFocus(true);
931-
compareInput();
932-
updateCaretPosition();
942+
setFocus(true);
943+
compareInput();
944+
updateCaretPosition();
933945
});
934946

935947
//handle keyboard events

public/js/userconfig.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,27 @@ function previewTheme(name) {
141141
function setTheme(name) {
142142
config.theme = name;
143143
$("#currentTheme").attr("href", `themes/${name}.css`);
144-
firebase.analytics().logEvent('changedTheme', {
145-
theme: name
146-
});
144+
try{
145+
firebase.analytics().logEvent('changedTheme', {
146+
theme: name
147+
});
148+
}catch(e){
149+
console.log("Analytics unavailable");
150+
}
147151
}
148152

149153
function changeLanguage(language) {
150154
if (language == null || language == undefined) {
151155
language = "english";
152156
}
153157
config.language = language;
154-
firebase.analytics().logEvent('changedLanguage', {
155-
language: language
156-
});
158+
try{
159+
firebase.analytics().logEvent('changedLanguage', {
160+
language: language
161+
});
162+
}catch(e){
163+
console.log("Analytics unavailable");
164+
}
157165
saveConfigToCookie();
158166
}
159167

0 commit comments

Comments
 (0)