做了个啥?
用GPT生成了一个tampermonkey的脚本在鸡腿页面可以实现统计数据
效果

tampermonkey代码
// ==UserScript==
// @name NS Yearly Summary
// @namespace http://tampermonkey.net/
// @version 2.1
// @description 生成年度总结并展示类似年终报告的页面,包含加入时间等详细信息,以及完整统计数据展示
// @author KefIe with GPT 4o
// @match https://www.nodeseek.comhttp://127.0.0.1:5001/credit
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @run-at document-end
// ==/UserScript==
(async function () {
'use strict';
// 格式化数据,将原始数组转换为 JSON 对象
function formatData(rawData) {
if (!rawData || !rawData.success || !Array.isArray(rawData.data)) {
throw new Error('数据格式无效');
}
// 将数据转换为所需格式
return rawData.data.map(item => ({
change: item[0], // 加/扣分值
balance: item[1], // 当前余额
reason: item[2], // 操作原因
timestamp: new Date(item[3]), // 时间戳
}));
}
// 筛选出从 2024-01-01 开始的数据
function filterData(data) {
const startDate = new Date('2024-01-01T00:00:00Z');
return data.filter(item => item.timestamp >= startDate);
}
// 生成年度总结
function generateSummary(allData, filteredData) {
const summary = {
joinDate: allData[allData.length - 1]?.timestamp, // 加入时间为最早的记录时间
totalDays: 0,
totalGains: 0,
totalLosses: 0,
totalEntries: filteredData.length,
details: {
"签到收益": { total: 0, count: 0, earliest: null, latest: null },
"回帖奖励": { total: 0, count: 0 },
"发帖奖励": { total: 0, count: 0 },
"被投喂鸡腿": { total: 0, count: 0 },
"投喂鸡腿": { total: 0, count: 0 },
"认定为轻度灌水": { total: 0, count: 0 },
"公开帖子私有化": { total: 0, count: 0 },
"内板代价": { total: 0, count: 0 },
"代理相关须发内板": { total: 0, count: 0 },
"其他": { total: 0, count: 0 }
},
maxDeduction: { reason: '', amount: 0 }, // 最大扣分项
totalDeductions: { total: 0, count: 0 } // 扣分总计
};
filteredData.forEach(item => {
const { change, reason, timestamp } = item;
if (change > 0) {
summary.totalGains = change;
if (reason.includes("签到收益")) {
summary.details["签到收益"].total = change;
summary.details["签到收益"].count ;
if (!summary.details["签到收益"].earliest || timestamp summary.details["签到收益"].latest) {
summary.details["签到收益"].latest = timestamp;
}
} else if (reason.includes("回帖奖励")) {
summary.details["回帖奖励"].total = change;
summary.details["回帖奖励"].count ;
} else if (reason.includes("发帖奖励")) {
summary.details["发帖奖励"].total = change;
summary.details["发帖奖励"].count ;
} else if (reason.includes("被") && reason.includes("投喂鸡腿")) {
summary.details["被投喂鸡腿"].total = change;
summary.details["被投喂鸡腿"].count ;
} else {
summary.details["其他"].total = change;
summary.details["其他"].count ;
}
} else {
const absChange = Math.abs(change);
summary.totalLosses = absChange;
summary.totalDeductions.total = absChange;
summary.totalDeductions.count ;
if (absChange > summary.maxDeduction.amount) {
summary.maxDeduction = { reason, amount: absChange };
}
if (reason.includes("轻度灌水")) {
summary.details["认定为轻度灌水"].total = absChange;
summary.details["认定为轻度灌水"].count ;
} else if (reason.includes("公开帖子私有化")) {
summary.details["公开帖子私有化"].total = absChange;
summary.details["公开帖子私有化"].count ;
} else if (reason.includes("内板代价")) {
summary.details["内板代价"].total = absChange;
summary.details["内板代价"].count ;
} else if (reason.includes("代理相关须发内板")) {
summary.details["代理相关须发内板"].total = absChange;
summary.details["代理相关须发内板"].count ;
} else if (reason.includes("投喂鸡腿")) {
summary.details["投喂鸡腿"].total = absChange;
summary.details["投喂鸡腿"].count ;
} else {
summary.details["其他"].total = absChange;
summary.details["其他"].count ;
}
}
});
summary.totalDays = Math.floor((new Date() - summary.joinDate) / (1000 * 60 * 60 * 24));
return summary;
}
// 显示年度总结页面
function displaySummary(summary) {
// 清空页面内容
document.body.innerHTML = '';
const container = document.createElement('div');
container.style.fontFamily = 'Arial, sans-serif';
container.style.margin = '20px';
container.style.opacity = '0';
container.style.transition = 'opacity 1s';
document.body.appendChild(container);
const sections = [];
// 第一版:年度总结标题
sections.push(`2024 年度总结
`);
// 第二版:加入时间
sections.push(
`您是在 ${summary.joinDate.toLocaleDateString()} 加入的NS,距离现在已经有 ${summary.totalDays} 天。
`
);
// 第三版:总加分、总扣分
sections.push(
`今年共计加了 ${summary.totalGains} 分,扣了 ${summary.totalLosses} 分,总计 ${summary.totalGains - summary.totalLosses} 分。
`
);
// 第四版:签到统计
const signIn = summary.details["签到收益"];
if (signIn.count > 0) {
const avgGain = (signIn.total / signIn.count).toFixed(2);
const comment = avgGain < 5 ? "明年可能还是拿低保的好" : "你真是个幸运的人";
sections.push(
`今年共计签到 ${signIn.count} 次,
最早一次签到是在 ${signIn.earliest.toLocaleTimeString()},
最晚一次签到是在 ${signIn.latest.toLocaleTimeString()},
平均每次获得鸡腿 ${avgGain} 个。${comment}
`
);
}
// 第五版:扣分统计
// 添加扣分统计显示逻辑
if (summary.totalDeductions.total === 0) {
// 如果没有扣分记录,显示“你真是个乖宝宝”
sections.push('你真是个乖宝宝
');
} else {
// 显示扣分统计
sections.push('扣分统计
');
sections.push(
`总计扣分 ${summary.totalDeductions.total} 分,次数 ${summary.totalDeductions.count}。
`
);
// 添加每种扣分项的详细统计
Object.keys(summary.details).forEach(key => {
if (key.includes("轻度灌水") || key.includes("公开帖子私有化") || key.includes("内板代价") || key.includes("代理相关须发内板")) {
const detail = summary.details[key];
sections.push(
`${key}: 总计扣分 ${detail.total} 分,次数 ${detail.count}
`
);
}
});
}
// 第六版:投喂统计
const feeding = summary.details["被投喂鸡腿"];
if (feeding.count > 0) {
sections.push(
`今年你被投喂了 ${feeding.count} 次,希望明年还能看到你更好的作品。
`
);
}
// 第七版:完整统计数据
sections.push('完整统计数据
');
Object.keys(summary.details).forEach(key => {
const detail = summary.details[key];
sections.push(
`${key}: 总计 ${detail.total} 分,次数 ${detail.count}
`
);
});
// 插入内容
sections.forEach((section, index) => {
const sectionElement = document.createElement('div');
sectionElement.innerHTML = section;
sectionElement.style.opacity = '0';
sectionElement.style.transition = 'opacity 1s';
sectionElement.style.marginBottom = '20px';
container.appendChild(sectionElement);
setTimeout(() => {
sectionElement.style.opacity = '1';
}, index * 1000); // 每段内容依次淡入
});
// 动态淡入效果
setTimeout(() => {
container.style.opacity = '1';
}, 100);
}
// 获取 Cookie
function getCookie() {
return document.cookie;
}
// 封装 GM_xmlhttpRequest 为 Promise
function gmRequest(options) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
...options,
onload: (response) => {
if (response.status >= 200 && response.status {
reject(error);
}
});
});
}
// 动态创建一个按钮并固定在页面中间
const button = document.createElement('button');
button.innerText = '开始获取你的ns年终报告';
button.id = 'centered-button';
document.body.appendChild(button);
// 添加样式,让按钮固定在页面中间
GM_addStyle(`
#centered-button {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 10000;
padding: 15px 30px;
font-size: 16px;
cursor: pointer;
background-color: #007BFF;
color: white;
border: none;
border-radius: 5px;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
}
#centered-button:hover {
background-color: #0056b3;
}
`);
let flag = false; // 防止重复点击
// 给按钮添加点击事件
button.addEventListener('click', async () => {
if (flag) return; // 防止重复执行
flag = true;
let allData = []; // 存储所有页面的数据
const lastPageElement = document.querySelectorAll('.pager-pos');
let lastPageNum = 1;
// 获取最后一页页码
if (lastPageElement.length > 2) {
lastPageNum = parseInt(
lastPageElement[lastPageElement.length - 2].href.replace('https://www.nodeseek.comhttp://127.0.0.1:5001/credit#/p-', '')
);
}
const cookies = getCookie(); // 获取本地 Cookie
for (let i = 1; i <= lastPageNum; i ) {
console.log(`正在获取第 ${i}/${lastPageNum} 页的数据`);
button.innerText = `正在获取第 ${i}/${lastPageNum} 页的数据...`;
try {
const response = await gmRequest({
method: 'GET',
url: `https://www.nodeseek.com/api/accounthttp://127.0.0.1:5001/credit/page-${i}`, // 替换为实际的 API URL
headers: {
'Content-Type': 'application/json',
cookie: cookies,
},
});
const rawData = JSON.parse(response.responseText);
const formattedData = formatData(rawData);
// 合并数据
allData = [...allData, ...formattedData];
} catch (error) {
console.error(`第 ${i} 页请求失败:`, error);
alert(`第 ${i} 页请求失败,请检查控制台日志!`);
button.innerText = '点击重新获取'; // 恢复按钮文字
flag = false;
return;
}
}
// 筛选出从 2024-01-01 开始的数据
const filteredData = filterData(allData);
console.log('筛选后的数据:', filteredData);
// 生成总结
const summary = generateSummary(allData, filteredData);
console.log('年度总结:', summary);
// 动态展示总结
displaySummary(summary);
flag = false; // 重置状态
});
})();

牛逼了
计划更新1.增加更多属性修复bug1.投喂鸡腿被计入扣分2.页面超过100页,无法获取真实加入时间NS论坛官方版本已经发布,效果和数据也更加真实,后续不再更新,感谢论坛支持
@3az7qmfd #3 不到一年干到6级,大佬啊