让gpt随便糊了一个,要注意不要频繁拉取数据,以免对服务器造成压力
@Unique 佬写过一个ui好看,功能更全的(不知道会不会发布)
油猴获取当天点赞数
也可以直接在控制台输出
(function () {
const button = document.createElement("button");
button.textContent = "获取今天的点赞数";
button.style.position = "fixed";
button.style.top = "10px";
button.style.right = "10px";
button.style.zIndex = "1000";
document.body.appendChild(button);
button.addEventListener("click", async function () {
const username = Discourse.User.current().username;
const csrfToken = document
.querySelector('meta[name="csrf-token"]')
.getAttribute("content");
async function fetchAndFilterHeartReactions(username) {
const response = await fetch(
`https://linux.do/user_actions.json?limit=100&offset=0&username=${username}&filter=1`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
"X-Csrf-Token": csrfToken,
"X-Requested-With": "XMLHttpRequest",
},
credentials: "include",
}
);
const data = await response.json();
const todayUTC = new Date().toISOString().slice(0, 10);
console.log("当前UTC日期:", todayUTC);
const todayActions = data.user_actions.filter(
(action) => action.created_at.slice(0, 10) === todayUTC
);
return {
count: todayActions.length,
date: todayUTC,
};
}
const result = await fetchAndFilterHeartReactions(username);
alert(`时间(UTC): ${result.date}\n今天点赞数: ${result.count}`);
});
})();