$(".pageLogin .register input").keyup(e => { if (e.key == "Enter") { signUp(); } }) $(".pageLogin .register .button").click(e => { signUp(); }) $(".pageLogin .login input").keyup(e => { if (e.key == "Enter") { signIn(); } }) $(".pageLogin .login .button").click(e => { signIn(); }) $(".signOut").click(e => { signOut(); }) $(".pageAccount .loadMoreButton").click(e => { loadMoreLines(); }) $(".pageLogin #forgotPasswordButton").click(e => { let email = prompt("Email address"); if(email){ firebase.auth().sendPasswordResetEmail(email).then(function() { // Email sent. showNotification("Email sent",2000); }).catch(function(error) { // An error happened. showNotification(error.message,5000); }); } }) function showSignOutButton() { $(".signOut").removeClass('hidden').css("opacity",1); } function hideSignOutButton() { $(".signOut").css("opacity",0).addClass('hidden'); } function signIn() { $(".pageLogin .preloader").removeClass('hidden'); let email = $(".pageLogin .login input")[0].value; let password = $(".pageLogin .login input")[1].value; if($(".pageLogin .login #rememberMe input").prop('checked')){ //remember me firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL).then(function() { return firebase.auth().signInWithEmailAndPassword(email, password).then(e => { changePage('test'); }).catch(function(error) { showNotification(error.message, 5000); $(".pageLogin .preloader").addClass('hidden'); }); }) }else{ //dont remember firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION).then(function() { return firebase.auth().signInWithEmailAndPassword(email, password).then(e => { changePage('test'); }).catch(function(error) { showNotification(error.message, 5000); $(".pageLogin .preloader").addClass('hidden'); }); }) } } function signUp() { $(".pageLogin .preloader").removeClass('hidden'); let nname = $(".pageLogin .register input")[0].value; let email = $(".pageLogin .register input")[1].value; let password = $(".pageLogin .register input")[2].value; let passwordVerify = $(".pageLogin .register input")[3].value; const namecheck = firebase.functions().httpsCallable('checkNameAvailability') namecheck({name:nname}).then(d => { if(d.data === 0){ showNotification("Name unavailable", 3000); $(".pageLogin .preloader").addClass('hidden'); return; }else if(d.data === 1){ if (password != passwordVerify) { showNotification("Passwords do not match", 3000); $(".pageLogin .preloader").addClass('hidden'); return; } firebase.auth().createUserWithEmailAndPassword(email, password).then(user => { // Account has been created here. let usr = user.user; usr.updateProfile({ displayName: name }).then(function() { // Update successful. showNotification("Account created", 2000); try{ firebase.analytics().logEvent("accountCreated", usr.uid); }catch(e){ console.log("Analytics unavailable"); } $(".pageLogin .preloader").addClass('hidden'); changePage('account'); }).catch(function(error) { // An error happened. usr.delete().then(function() { // User deleted. showNotification("Name invalid", 2000); $(".pageLogin .preloader").addClass('hidden'); }).catch(function(error) { // An error happened. $(".pageLogin .preloader").addClass('hidden'); }); }); }).catch(function(error) { // Handle Errors here. var errorCode = error.code; var errorMessage = error.message; showNotification(errorMessage, 5000); $(".pageLogin .preloader").addClass('hidden'); }); } }) } function signOut() { firebase.auth().signOut().then(function() { showNotification("Signed out", 2000); updateAccountLoginButton(); changePage('login'); dbSnapshot = null; }).catch(function(error) { showNotification(error.message, 5000); }); } firebase.auth().onAuthStateChanged(function(user) { if (user) { // User is signed in. updateAccountLoginButton(); accountIconLoading(true); db_getUserSnapshot().then(e => { console.log('DB snapshot ready'); accountIconLoading(false); }); var displayName = user.displayName; var email = user.email; var emailVerified = user.emailVerified; var photoURL = user.photoURL; var isAnonymous = user.isAnonymous; var uid = user.uid; var providerData = user.providerData; // showNotification('Signed in', 1000); $(".pageLogin .preloader").addClass('hidden'); verifyUsername(); $("#menu .button.account .text").text(displayName); } }); var resultHistoryChart = new Chart($(".pageAccount #resultHistoryChart"), { animationSteps: 60, type: 'line', data: { datasets: [ { label: "wpm", fill: false, data: [], borderColor: '#f44336', borderWidth: 2, // trendlineLinear: { // style: "rgba(244,67,54,.25)", // lineStyle: "solid", // width: 1 // } trendlineLinear: { style: "rgba(255,105,180, .8)", lineStyle: "dotted", width: 2 } }, ], }, options: { tooltips: { // Disable the on-canvas tooltip enabled: true, titleFontFamily: "Roboto Mono", bodyFontFamily: "Roboto Mono", intersect: false, custom: function(tooltip) { if (!tooltip) return; // disable displaying the color box; tooltip.displayColors = false; }, callbacks : { // HERE YOU CUSTOMIZE THE LABELS title: function(){ return; }, beforeLabel : function(tooltipItem, data) { let resultData = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]; let label = `${data.datasets[tooltipItem.datasetIndex].label}: ${tooltipItem.yLabel}` + '\n' + `acc: ${resultData.acc}` + '\n\n' + `mode: ${resultData.mode} `; if(resultData.mode == "time"){ label += resultData.mode2; }else if(resultData.mode == "words"){ label += resultData.mode2; } let diff = resultData.difficulty; if(diff == undefined){ diff = "normal" } label += '\n' + `difficulty: ${diff}` label += '\n' + `punctuation: ${resultData.punctuation}` + '\n' + `language: ${resultData.language}` + '\n\n' + `date: ${moment(resultData.timestamp).format('DD MMM YYYY HH:mm')}`; return label; }, label : function(tooltipItem, data) { return; }, afterLabel : function(tooltipItem, data) { return; }, } }, animation: { duration: 250 }, legend: { display: false, labels: { fontFamily: "Roboto Mono", fontColor: "#ffffff" } }, responsive: true, // maintainAspectRatio: false, // tooltips: { // mode: 'index', // intersect: false, // }, hover: { mode: 'nearest', intersect: true }, scales: { xAxes: [{ ticks: { fontFamily: "Roboto Mono" }, type: 'time', bounds: 'ticks', distribution: 'series', display: false, scaleLabel: { display: true, labelString: 'Date' }, }], yAxes: [{ ticks: { fontFamily: "Roboto Mono", beginAtZero: true }, display: true, scaleLabel: { display: false, labelString: 'Words per Minute' } }] }, } }); Object.keys(words).forEach(language => { $(".pageAccount .content .filterButtons .buttons.languages") .append(`
`); }) let activeFilters = ["all"]; $(document).ready(e =>{ activeFilters = config.resultFilters; // console.log(activeFilters); if(activeFilters.includes("all")){ toggleFilterButton("all") }else{ activeFilters.forEach(filter => { toggleFilterButton(filter); }) } }) function toggleFilterButton(filter){ const element = $(`.pageAccount .content .filterButtons .button[filter=${filter}]`); if(element.hasClass('active')){ //disable that filter if(filter == 'all' || filter == 'none'){ return; }else if(filter == "mode_words"){ // $.each($(`.pageAccount .content .filterButtons .buttons.wordsFilter .button`),(index,obj)=>{ // let f = $(obj).attr('filter') // disableFilterButton(f) // }) }else if(filter == "mode_time"){ // $.each($(`.pageAccount .content .filterButtons .buttons.timeFilter .button`),(index,obj)=>{ // let f = $(obj).attr('filter') // disableFilterButton(f) // }) }else if(filter == "punc_off"){ enableFilterButton("punc_on"); }else if(filter == "punc_on"){ enableFilterButton("punc_off"); } disableFilterButton(filter); disableFilterButton('all'); }else{ //enable that filter disableFilterButton('none'); if(filter == 'all'){ $.each($(`.pageAccount .content .filterButtons .button`),(index,obj)=>{ let f = $(obj).attr('filter'); if(f != 'none'){ enableFilterButton(f); } }) }else if(filter == 'none'){ disableFilterButton('all'); $.each($(`.pageAccount .content .filterButtons .button`),(index,obj)=>{ let f = $(obj).attr('filter'); if(f != 'none'){ disableFilterButton(f); } }) } // else if(filter == "mode_words"){ // $.each($(`.pageAccount .content .filterButtons .buttons.wordsFilter .button`),(index,obj)=>{ // let f = $(obj).attr('filter'); // enableFilterButton(f); // }) // }else if(filter == "mode_time"){ // $.each($(`.pageAccount .content .filterButtons .buttons.timeFilter .button`),(index,obj)=>{ // let f = $(obj).attr('filter'); // enableFilterButton(f); // }) // }else if(['10','25','50','100','200'].includes(filter)){ // enableFilterButton('words'); // }else if(['15','30','60','120'].includes(filter)){ // enableFilterButton('time'); // } enableFilterButton(filter); } updateActiveFilters(); } function disableFilterButton(filter){ const element = $(`.pageAccount .content .filterButtons .button[filter=${filter}]`); element.removeClass('active'); } function enableFilterButton(filter){ const element = $(`.pageAccount .content .filterButtons .button[filter=${filter}]`); element.addClass('active'); } function updateActiveFilters(){ activeFilters = []; $.each($(".pageAccount .filterButtons .button"),(i,obj)=>{ if($(obj).hasClass('active')){ activeFilters.push($(obj).attr('filter')); } }) refreshAccountPage(); } function showChartPreloader(){ $(".pageAccount .group.chart .preloader").stop(true,true).animate({ opacity: 1 },125); } function hideChartPreloader(){ $(".pageAccount .group.chart .preloader").stop(true,true).animate({ opacity: 0 },125); } $('.pageAccount .filterButtons').click('.button',e =>{ const filter = $(e.target).attr('filter'); toggleFilterButton(filter); config.resultFilters = activeFilters; saveConfigToCookie(); }) let filteredResults = []; let visibleTableLines = 0; function loadMoreLines(){ if(filteredResults == [] || filteredResults.length == 0) return; for(let i = visibleTableLines; i < visibleTableLines+10; i++){ result = filteredResults[i]; if(result == undefined) continue; let withpunc = ''; if (result.punctuation) { withpunc = '