直接在 linuxDo 任意界面按 F12 打开控制台,粘贴进去执行
(async function analyzeCheckins() {
console.log("正在获取数据...");
try {
// 1. 请求数据 (复用当前浏览器的登录凭证)
const response = await fetch('/rewinds/9.json');
if (!response.ok) throw new Error('网络请求失败');
const json = await response.json();
const allData = json.report.data;
// 2. 定义时间范围 (今天往前推100天)
const today = new Date();
// 将时间设为今天的最后一刻,确保包含今天
today.setHours(23, 59, 59, 999);
const pastDate = new Date(today);
pastDate.setDate(today.getDate() - 99); // 往前推99天(共100天)
// 将开始时间设为当天的0点
pastDate.setHours(0, 0, 0, 0);
console.log(`%c📅 统计范围: ${pastDate.toISOString().split('T')[0]} 至 ${today.toISOString().split('T')[0]} (近100天)`, "color: #409EFF; font-weight: bold;");
// 3. 筛选数据
// 逻辑:日期在范围内 && visited 为 false
const missedDays = allData.filter(item => {
const itemDate = new Date(item.date);
// 这里为了避免时区导致的误差,统一比较时间戳或日期字符串
// 简单处理:将item.date设为当地时间0点进行比较
const currentItemDate = new Date(item.date + 'T00:00:00');
return currentItemDate >= pastDate && currentItemDate <= today && item.visited === false;
});
// 4. 格式化输出数据
const tableData = missedDays.map(item => {
const dateObj = new Date(item.date);
const weekDays = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
return {
"未访问日期": item.date,
"星期": weekDays[dateObj.getDay()],
"发帖数": item.post_count // 虽然没访问通常是0,但也展示一下以防万一
};
});
// 5. 输出结果
console.group(`%c📊 分析报告`, "font-size: 14px; font-weight: bold;");
if (missedDays.length === 0) {
console.log(`%c🎉 太棒了!这 100 天内你全勤访问!`, "color: green; font-weight: bold; font-size: 16px;");
} else {
console.log(`%c⚠️ 在过去的 100 天里,你共有 ${missedDays.length} 天 没有访问。`, "color: #F56C6C; font-weight: bold; font-size: 16px;");
console.log("详细列表如下:");
// 使用 console.table 打印美观的表格
console.table(tableData);
}
console.groupEnd();
} catch (error) {
console.error("发生错误:", error);
}
})();