油猴脚本。打开论坛自动签到。问的gpt。可能有bug,自己问gpt改吧。。。
// ==UserScript==
// @name Nodeloc 自动签到+试试手气
// @namespace http://tampermonkey.net/
// @version 1.1
// @description 每天首次打开 Nodeloc 时自动签到并试试手气
// @author houmusic
// @match https://www.nodeloc.com/*
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
(function () {
'use strict';
// 检查今天是否已经执行过
const today = new Date().toLocaleDateString();
const lastCheckDate = GM_getValue('lastCheckDate', '');
if (lastCheckDate === today) {
console.log('今天已经自动签到过了!');
return;
}
// 定时器等待页面加载
const waitForElement = (selector, timeout = 10000) => {
return new Promise((resolve, reject) => {
const interval = 100;
let elapsed = 0;
const timer = setInterval(() => {
const element = document.querySelector(selector);
if (element) {
clearInterval(timer);
resolve(element);
}
elapsed += interval;
if (elapsed >= timeout) {
clearInterval(timer);
reject(`元素 ${selector} 未找到`);
}
}, interval);
});
};
// 自动签到逻辑
async function autoCheckIn() {
try {
// 点击下拉按钮以展开签到选项
const dropdownButton = await waitForElement('button[title="签到"]');
dropdownButton.click();
console.log('展开签到选项!');
// 等待“签到”按钮
const checkinButton = await waitForElement('#checkinButton');
checkinButton.click();
console.log('签到成功!');
// 等待“今天试试手气”按钮
const randomCheckinButton = await waitForElement('#randomcheckinButton');
randomCheckinButton.click();
console.log('试试手气成功!');
// 记录签到日期
GM_setValue('lastCheckDate', today);
} catch (error) {
console.error('自动签到失败:', error);
}
}
// 执行自动签到
autoCheckIn();
})();