mirror of
https://github.com/ssyyhhrr/stewardle.git
synced 2025-11-14 04:43:49 -05:00
Version Check on Load
This commit is contained in:
51
app.js
51
app.js
@@ -148,30 +148,32 @@ async function updateDrivers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function processStats(dotd = false) {
|
function processStats(dotd = false) {
|
||||||
let date = dayjs().format("YYYY-MM-DD")
|
const date = dayjs().format("YYYY-MM-DD");
|
||||||
|
|
||||||
|
let statsFile = {};
|
||||||
if (fs.existsSync(statsPath)) {
|
if (fs.existsSync(statsPath)) {
|
||||||
let statsFile = JSON.parse(fs.readFileSync(statsPath))
|
statsFile = JSON.parse(fs.readFileSync(statsPath));
|
||||||
if (statsFile.hasOwnProperty(date)) {
|
|
||||||
if (statsFile[date]["visits"] < stats["visits"]) {
|
|
||||||
statsFile[date]["visits"] = stats["visits"]
|
|
||||||
} else {
|
|
||||||
statsFile[date]["visits"] += stats["visits"]
|
|
||||||
stats["visits"] = statsFile[date]["visits"]
|
|
||||||
}
|
|
||||||
if (statsFile[date]["guesses"] < stats["guesses"]) {
|
|
||||||
statsFile[date]["guesses"] = stats["guesses"]
|
|
||||||
} else {
|
|
||||||
statsFile[date]["guesses"] += stats["guesses"]
|
|
||||||
stats["guesses"] = statsFile[date]["guesses"]
|
|
||||||
}
|
|
||||||
if (!statsFile[date].hasOwnProperty("driver") && stats.hasOwnProperty("driver")) {
|
|
||||||
statsFile[date]["driver"] = stats["driver"]
|
|
||||||
}
|
|
||||||
} else if (dotd) {
|
|
||||||
statsFile[date] = stats
|
|
||||||
}
|
|
||||||
fs.writeFileSync(statsPath, JSON.stringify(statsFile))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dotd) {
|
||||||
|
statsFile[date] = {
|
||||||
|
visits: stats.visits,
|
||||||
|
guesses: stats.guesses,
|
||||||
|
driver: stats.driver,
|
||||||
|
};
|
||||||
|
} else if (statsFile[date]) {
|
||||||
|
statsFile[date].visits = Math.max(statsFile[date].visits, stats.visits);
|
||||||
|
statsFile[date].guesses = Math.max(statsFile[date].guesses, stats.guesses);
|
||||||
|
statsFile[date].driver = stats.driver || statsFile[date].driver;
|
||||||
|
} else {
|
||||||
|
statsFile[date] = {
|
||||||
|
visits: stats.visits,
|
||||||
|
guesses: stats.guesses,
|
||||||
|
driver: stats.driver,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(statsPath, JSON.stringify(statsFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
function dotd() {
|
function dotd() {
|
||||||
@@ -237,9 +239,8 @@ function server() {
|
|||||||
stats.visits++
|
stats.visits++
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get("/stats", (req, res) => {
|
app.get("/version", (req, res) => {
|
||||||
let rawStatsFile = fs.readFileSync(statsPath)
|
res.send(version)
|
||||||
res.json(JSON.parse(rawStatsFile))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get("/winner", (req, res) => {
|
app.get("/winner", (req, res) => {
|
||||||
|
|||||||
@@ -503,6 +503,17 @@ function fillStats(stats, scores) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
fetch(`${window.location.href}version`).then(res => {
|
||||||
|
res.text().then(result => {
|
||||||
|
if (result !== localStorage.version) {
|
||||||
|
localStorage.removeItem("guesses")
|
||||||
|
localStorage.removeItem("version")
|
||||||
|
localStorage.removeItem("answers")
|
||||||
|
localStorage.version = result
|
||||||
|
location.reload()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
if (localStorage.getItem("highContrast") === null) {
|
if (localStorage.getItem("highContrast") === null) {
|
||||||
document.getElementById("highContrast").disabled = true
|
document.getElementById("highContrast").disabled = true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user