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:
49
app.js
49
app.js
@@ -148,30 +148,32 @@ async function updateDrivers() {
|
||||
}
|
||||
|
||||
function processStats(dotd = false) {
|
||||
let date = dayjs().format("YYYY-MM-DD")
|
||||
const date = dayjs().format("YYYY-MM-DD");
|
||||
|
||||
let statsFile = {};
|
||||
if (fs.existsSync(statsPath)) {
|
||||
let statsFile = JSON.parse(fs.readFileSync(statsPath))
|
||||
if (statsFile.hasOwnProperty(date)) {
|
||||
if (statsFile[date]["visits"] < stats["visits"]) {
|
||||
statsFile[date]["visits"] = stats["visits"]
|
||||
statsFile = JSON.parse(fs.readFileSync(statsPath));
|
||||
}
|
||||
|
||||
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"]
|
||||
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))
|
||||
statsFile[date] = {
|
||||
visits: stats.visits,
|
||||
guesses: stats.guesses,
|
||||
driver: stats.driver,
|
||||
};
|
||||
}
|
||||
|
||||
fs.writeFileSync(statsPath, JSON.stringify(statsFile));
|
||||
}
|
||||
|
||||
function dotd() {
|
||||
@@ -237,9 +239,8 @@ function server() {
|
||||
stats.visits++
|
||||
})
|
||||
|
||||
app.get("/stats", (req, res) => {
|
||||
let rawStatsFile = fs.readFileSync(statsPath)
|
||||
res.json(JSON.parse(rawStatsFile))
|
||||
app.get("/version", (req, res) => {
|
||||
res.send(version)
|
||||
})
|
||||
|
||||
app.get("/winner", (req, res) => {
|
||||
|
||||
@@ -503,6 +503,17 @@ function fillStats(stats, scores) {
|
||||
}
|
||||
|
||||
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) {
|
||||
document.getElementById("highContrast").disabled = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user