fixed global of undefined error

This commit is contained in:
Jack 2020-09-17 00:06:26 +01:00
parent 7e2c0e4840
commit e5412e5892

View file

@ -1981,31 +1981,22 @@ function showResult(difficultyFailed = false) {
console.log("Analytics unavailable");
}
const lbUpIcon = `<i class="fas fa-angle-up"></i>`;
const lbDownIcon = `<i class="fas fa-angle-down"></i>`;
const lbRightIcon = `<i class="fas fa-angle-right"></i>`;
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 = `<i class="fas fa-angle-up"></i>`;
const lbDownIcon = `<i class="fas fa-angle-down"></i>`;
const lbRightIcon = `<i class="fas fa-angle-right"></i>`;
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 += ` <span class="lbChange" aria-label="You've gained ${globalLbDiff} position${sString}" data-balloon-pos="up">(${lbUpIcon}${globalLbDiff})</span>`;
} else if (globalLbDiff === 0) {
globalLbString += ` <span class="lbChange" aria-label="Your position remained the same" data-balloon-pos="up">(${lbRightIcon}${globalLbDiff})</span>`;
} else if (globalLbDiff < 0) {
globalLbString += ` <span class="lbChange" aria-label="You've lost ${globalLbDiff} position${sString}" data-balloon-pos="up">(${lbDownIcon}${globalLbDiff})</span>`;
}
}
//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 += ` <span class="lbChange" aria-label="You've gained ${dailyLbDiff} position${sString}" data-balloon-pos="up">(${lbUpIcon}${dailyLbDiff})</span>`;
} else if (dailyLbDiff === 0) {
dailyLbString += ` <span class="lbChange" aria-label="Your position remained the same" data-balloon-pos="up">(${lbRightIcon}${dailyLbDiff})</span>`;
} else if (dailyLbDiff < 0) {
dailyLbString += ` <span class="lbChange" aria-label="You've lost ${dailyLbDiff} position${sString}" data-balloon-pos="up">(${lbDownIcon}${dailyLbDiff})</span>`;
}
}
$("#result .stats .leaderboards .bottom").html(
globalLbString + "<br>" + 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 += ` <span class="lbChange" aria-label="You've gained ${globalLbDiff} position${sString}" data-balloon-pos="up">(${lbUpIcon}${globalLbDiff})</span>`;
} else if (globalLbDiff === 0) {
globalLbString += ` <span class="lbChange" aria-label="Your position remained the same" data-balloon-pos="up">(${lbRightIcon}${globalLbDiff})</span>`;
} else if (globalLbDiff < 0) {
globalLbString += ` <span class="lbChange" aria-label="You've lost ${globalLbDiff} position${sString}" data-balloon-pos="up">(${lbDownIcon}${globalLbDiff})</span>`;
}
}
);
//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 += ` <span class="lbChange" aria-label="You've gained ${dailyLbDiff} position${sString}" data-balloon-pos="up">(${lbUpIcon}${dailyLbDiff})</span>`;
} else if (dailyLbDiff === 0) {
dailyLbString += ` <span class="lbChange" aria-label="Your position remained the same" data-balloon-pos="up">(${lbRightIcon}${dailyLbDiff})</span>`;
} else if (dailyLbDiff < 0) {
dailyLbString += ` <span class="lbChange" aria-label="You've lost ${dailyLbDiff} position${sString}" data-balloon-pos="up">(${lbDownIcon}${dailyLbDiff})</span>`;
}
}
$("#result .stats .leaderboards .bottom").html(
globalLbString + "<br>" + 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