Skip to content

Instantly share code, notes, and snippets.

@cmbuckley
Last active January 18, 2023 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmbuckley/99c6467ea581037902fba98e3ce8467d to your computer and use it in GitHub Desktop.
Save cmbuckley/99c6467ea581037902fba98e3ce8467d to your computer and use it in GitHub Desktop.
How close am I to the Fanatic badge on Stack Overflow?
$.get('/users/daily-site-access/' + StackExchange.options.user.userId, t => {
eval(t.match(/var visited = {.+};/)[0]);
const firstYear = Object.keys(visited)[0],
firstMonth = Object.keys(visited[firstYear])[0],
firstDay = Object.keys(visited[firstYear][firstMonth])[0],
date = new Date(firstYear, firstMonth - 1, firstDay),
today = Date.now();
let days = [], seq = 0, streaks = [0], fewest = 100, fewestDate;
do {
days[++seq] = !!visited[date.getFullYear()][date.getMonth() + 1][date.getDate()];
if (days[seq]) { streaks[streaks.length - 1]++; } else if (streaks[streaks.length - 1]) { streaks.push(0); }
if (days.length >= 100) {
// find 100-day period with fewest non-visits
let missing = days.slice(-100).filter(v => v === false).length;
if (missing <= fewest) { fewest = missing; fewestDate = new Date(date); }
}
date.setDate(date.getDate() + 1);
} while (date < today);
console.log(Math.max(...streaks), streaks, fewest, fewestDate);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment