diff --git a/public/js/script.js b/public/js/script.js index ec0335b30..a4b77f24a 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -1981,31 +1981,22 @@ function showResult(difficultyFailed = false) { console.log("Analytics unavailable"); } - const lbUpIcon = ``; - const lbDownIcon = ``; - const lbRightIcon = ``; + if (config.mode === "time" && (mode2 == "15" || mode2 == "60")) { - //global - let globalLbString = ""; - const glb = e.data.globalLeaderboard; - const glbMemory = - dbSnapshot.lbMemory[config.mode + mode2].global; - let dontShowGlobalDiff = glbMemory == null ? true : false; - let globalLbDiff = null; - if (glb === null) { - globalLbString = "global: not found"; - } else if (glb.insertedAt === -1) { - globalLbDiff = glbMemory - glb.insertedAt; - updateLbMemory( - config.mode, - mode2, - "global", - glb.insertedAt - ); + const lbUpIcon = ``; + const lbDownIcon = ``; + const lbRightIcon = ``; - globalLbString = "global: not qualified"; - } else if (glb.insertedAt >= 0) { - if (glb.newBest) { + //global + let globalLbString = ""; + const glb = e.data.globalLeaderboard; + const glbMemory = + dbSnapshot.lbMemory[config.mode + mode2].global; + let dontShowGlobalDiff = glbMemory == null ? true : false; + let globalLbDiff = null; + if (glb === null) { + globalLbString = "global: not found"; + } else if (glb.insertedAt === -1) { globalLbDiff = glbMemory - glb.insertedAt; updateLbMemory( config.mode, @@ -2013,86 +2004,97 @@ function showResult(difficultyFailed = false) { "global", glb.insertedAt ); - let str = getPositionString(glb.insertedAt + 1); - globalLbString = `global: ${str}`; - } else { - globalLbDiff = glbMemory - glb.foundAt; - updateLbMemory(config.mode, mode2, "global", glb.foundAt); - let str = getPositionString(glb.foundAt + 1); - globalLbString = `global: ${str}`; - } - } - if (!dontShowGlobalDiff) { - let sString = - globalLbDiff === 1 || globalLbDiff === -1 ? "" : "s"; - if (globalLbDiff > 0) { - globalLbString += ` (${lbUpIcon}${globalLbDiff})`; - } else if (globalLbDiff === 0) { - globalLbString += ` (${lbRightIcon}${globalLbDiff})`; - } else if (globalLbDiff < 0) { - globalLbString += ` (${lbDownIcon}${globalLbDiff})`; - } - } - //daily - let dailyLbString = ""; - const dlb = e.data.dailyLeaderboard; - const dlbMemory = - dbSnapshot.lbMemory[config.mode + mode2].daily; - let dontShowDailyDiff = dlbMemory == null ? true : false; - let dailyLbDiff = null; - if (dlb === null) { - dailyLbString = "daily: not found"; - } else if (dlb.insertedAt === -1) { - dailyLbDiff = dlbMemory - dlb.insertedAt; - updateLbMemory(config.mode, mode2, "daily", dlb.insertedAt); - dailyLbString = "daily: not qualified"; - } else if (dlb.insertedAt >= 0) { - if (dlb.newBest) { - dailyLbDiff = dlbMemory - dlb.insertedAt; - updateLbMemory( - config.mode, - mode2, - "daily", - dlb.insertedAt - ); - let str = getPositionString(dlb.insertedAt + 1); - dailyLbString = `daily: ${str}`; - } else { - dailyLbDiff = dlbMemory - dlb.foundAt; - updateLbMemory(config.mode, mode2, "daily", dlb.foundAt); - let str = getPositionString(dlb.foundAt + 1); - dailyLbString = `daily: ${str}`; - } - } - if (!dontShowDailyDiff) { - let sString = - dailyLbDiff === 1 || dailyLbDiff === -1 ? "" : "s"; - if (dailyLbDiff > 0) { - dailyLbString += ` (${lbUpIcon}${dailyLbDiff})`; - } else if (dailyLbDiff === 0) { - dailyLbString += ` (${lbRightIcon}${dailyLbDiff})`; - } else if (dailyLbDiff < 0) { - dailyLbString += ` (${lbDownIcon}${dailyLbDiff})`; - } - } - $("#result .stats .leaderboards .bottom").html( - globalLbString + "
" + dailyLbString - ); - - saveLbMemory({ uid: firebase.auth().currentUser.uid, obj: dbSnapshot.lbMemory }).then( - (d) => { - if (d.data.returnCode === 1) { - // showNotification('config saved to db',1000); - } else { - showNotification( - `Error saving lb memory ${d.data.message}`, - 4000 + globalLbString = "global: not qualified"; + } else if (glb.insertedAt >= 0) { + if (glb.newBest) { + globalLbDiff = glbMemory - glb.insertedAt; + updateLbMemory( + config.mode, + mode2, + "global", + glb.insertedAt ); + let str = getPositionString(glb.insertedAt + 1); + globalLbString = `global: ${str}`; + } else { + globalLbDiff = glbMemory - glb.foundAt; + updateLbMemory(config.mode, mode2, "global", glb.foundAt); + let str = getPositionString(glb.foundAt + 1); + globalLbString = `global: ${str}`; + } + } + if (!dontShowGlobalDiff) { + let sString = + globalLbDiff === 1 || globalLbDiff === -1 ? "" : "s"; + if (globalLbDiff > 0) { + globalLbString += ` (${lbUpIcon}${globalLbDiff})`; + } else if (globalLbDiff === 0) { + globalLbString += ` (${lbRightIcon}${globalLbDiff})`; + } else if (globalLbDiff < 0) { + globalLbString += ` (${lbDownIcon}${globalLbDiff})`; } } - ); + //daily + let dailyLbString = ""; + const dlb = e.data.dailyLeaderboard; + const dlbMemory = + dbSnapshot.lbMemory[config.mode + mode2].daily; + let dontShowDailyDiff = dlbMemory == null ? true : false; + let dailyLbDiff = null; + if (dlb === null) { + dailyLbString = "daily: not found"; + } else if (dlb.insertedAt === -1) { + dailyLbDiff = dlbMemory - dlb.insertedAt; + updateLbMemory(config.mode, mode2, "daily", dlb.insertedAt); + dailyLbString = "daily: not qualified"; + } else if (dlb.insertedAt >= 0) { + if (dlb.newBest) { + dailyLbDiff = dlbMemory - dlb.insertedAt; + updateLbMemory( + config.mode, + mode2, + "daily", + dlb.insertedAt + ); + let str = getPositionString(dlb.insertedAt + 1); + dailyLbString = `daily: ${str}`; + } else { + dailyLbDiff = dlbMemory - dlb.foundAt; + updateLbMemory(config.mode, mode2, "daily", dlb.foundAt); + let str = getPositionString(dlb.foundAt + 1); + dailyLbString = `daily: ${str}`; + } + } + if (!dontShowDailyDiff) { + let sString = + dailyLbDiff === 1 || dailyLbDiff === -1 ? "" : "s"; + if (dailyLbDiff > 0) { + dailyLbString += ` (${lbUpIcon}${dailyLbDiff})`; + } else if (dailyLbDiff === 0) { + dailyLbString += ` (${lbRightIcon}${dailyLbDiff})`; + } else if (dailyLbDiff < 0) { + dailyLbString += ` (${lbDownIcon}${dailyLbDiff})`; + } + } + $("#result .stats .leaderboards .bottom").html( + globalLbString + "
" + dailyLbString + ); + + saveLbMemory({ uid: firebase.auth().currentUser.uid, obj: dbSnapshot.lbMemory }).then( + (d) => { + if (d.data.returnCode === 1) { + // showNotification('config saved to db',1000); + } else { + showNotification( + `Error saving lb memory ${d.data.message}`, + 4000 + ); + } + } + ); + } if ( e.data.dailyLeaderboard === null && e.data.globalLeaderboard === null