Skip to content

Commit a8d680c

Browse files
authored
增加控制台日志打印
``` [VPS续期脚本] 检查到期时间... Xserver VPS 自动续期脚本.user.js:95 [VPS续期脚本] 页面上的到期日: 2025-07-24 Xserver VPS 自动续期脚本.user.js:96 [VPS续期脚本] 明天的日期: 2025-07-22 Xserver VPS 自动续期脚本.user.js:105 [VPS续期脚本] 条件不满足:无需执行续期操作。 ```
1 parent c712fe9 commit a8d680c

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

renew.user.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,27 @@
5858
* @description 登录页面逻辑:自动填充并保存用户凭据。
5959
*/
6060
if (location.pathname.startsWith('/xapanel/login/xvps')) {
61+
console.log(`[VPS续期脚本] 当前在登录页面。`);
6162
const memberid = GM_getValue('memberid');
6263
const user_password = GM_getValue('user_password');
6364

6465
// 如果存在已保存的凭据且页面没有显示错误消息,则自动填充并登录
6566
if (memberid && user_password && !document.querySelector('.errorMessage')) {
67+
console.log(`[VPS续期脚本] 发现已保存的凭据,正在尝试自动登录...`);
6668
unsafeWindow.memberid.value = memberid;
6769
unsafeWindow.user_password.value = user_password;
6870
// 调用页面自带的登录函数
6971
unsafeWindow.loginFunc();
72+
} else {
73+
console.log(`[VPS续期脚本] 未发现凭据或页面有错误信息,等待用户手动操作。`);
7074
}
7175

7276
// 监听登录表单的提交事件,以便保存用户输入的凭据
73-
// 确保 jQuery 已加载
7477
if (typeof $ !== 'undefined') {
7578
$('#login_area').on('submit', () => {
7679
GM_setValue('memberid', unsafeWindow.memberid.value);
7780
GM_setValue('user_password', unsafeWindow.user_password.value);
81+
console.log(`[VPS续期脚本] 已保存新的用户凭据。`);
7882
});
7983
}
8084
}
@@ -86,22 +90,33 @@
8690
// 计算明天的日期,格式为 YYYY-MM-DD (瑞典时区格式)
8791
const tomorrow = new Date(Date.now() + 86400000).toLocaleDateString('sv');
8892
const expireDate = document.querySelector('tr:has(.freeServerIco) .contract__term')?.textContent;
93+
94+
console.log(`[VPS续期脚本] 检查到期时间...`);
95+
console.log(`[VPS续期脚本] 页面上的到期日: ${expireDate || '未找到'}`);
96+
console.log(`[VPS续期脚本] 明天的日期: ${tomorrow}`);
8997

9098
// 如果到期日是明天,则准备续期
9199
if (expireDate === tomorrow) {
100+
console.log(`[VPS续期脚本] 条件满足:到期日为明天。正在跳转到续期页面...`);
92101
const href = document.querySelector('tr:has(.freeServerIco) a[href^="/xapanel/xvps/server/detail?id="]').href;
93102
// 跳转到续期页面
94103
location.href = href.replace('detail?id', 'freevps/extend/index?id_vps');
104+
} else {
105+
console.log(`[VPS续期脚本] 条件不满足:无需执行续期操作。`);
95106
}
96107
}
97108

98109
/**
99110
* @description 续期申请页面逻辑:自动点击确认按钮。
100111
*/
101112
if (location.pathname.startsWith('/xapanel/xvps/server/freevps/extend/index')) {
113+
console.log(`[VPS续期脚本] 当前在续期申请页面。`);
102114
const extendButton = document.querySelector('[formaction="/xapanel/xvps/server/freevps/extend/conf"]');
103115
if (extendButton) {
116+
console.log(`[VPS续期脚本] 找到续期按钮,正在点击...`);
104117
extendButton.click();
118+
} else {
119+
console.log(`[VPS续期脚本] 未找到续期按钮。`);
105120
}
106121
}
107122

@@ -111,43 +126,49 @@
111126
*/
112127
if ((location.pathname.startsWith('/xapanel/xvps/server/freevps/extend/conf') || location.pathname.startsWith('/xapanel/xvps/server/freevps/extend/do')) && unsafeWindow.submit_button) {
113128
(async function() {
129+
console.log(`[VPS续期脚本] 当前在验证码页面,开始处理验证码...`);
114130
try {
115131
const img = document.querySelector('img[src^="data:"]');
116132
if (!img) {
117-
console.log('CAPTCHA image not found.');
133+
console.log('[VPS续期脚本] 未找到验证码图片。');
118134
return;
119135
}
136+
console.log('[VPS续期脚本] 已找到验证码图片,正在发送到API进行识别...');
120137

121138
const body = img.src;
122139
// 调用外部API来识别验证码图片
123140
const code = await fetch('https://captcha-120546510085.asia-northeast1.run.app', { method: 'POST', body }).then(r => r.text());
141+
console.log(`[VPS续期脚本] API返回验证码: ${code}`);
124142

125143
const input = document.querySelector('[placeholder="上の画像の数字を入力"]');
126144
if (input) {
127145
input.value = code;
146+
console.log(`[VPS续期脚本] 已将验证码填入输入框。`);
128147
}
129148

130149
// 处理 Cloudflare Turnstile 人机验证
131150
const cf = document.querySelector('.cf-turnstile [name=cf-turnstile-response]');
132151
if (cf) {
133-
// 如果令牌已经存在,直接点击提交
152+
console.log(`[VPS续期脚本] 正在处理 Cloudflare Turnstile...`);
134153
if (cf.value) {
154+
console.log(`[VPS续期脚本] Cloudflare 令牌已存在,直接提交表单。`);
135155
unsafeWindow.submit_button.click();
136156
return;
137157
}
138-
// 如果令牌尚不存在,则使用 MutationObserver 监听其值的变化
158+
console.log(`[VPS续期脚本] Cloudflare 令牌不存在,设置监听器等待生成...`);
139159
// 一旦 cf-turnstile-response 的 value 被填充,就立即点击提交按钮
140160
new MutationObserver((mutationsList, observer) => {
141161
for(const mutation of mutationsList) {
142162
if (mutation.type === 'attributes' && mutation.attributeName === 'value' && cf.value) {
163+
console.log(`[VPS续期脚本] Cloudflare 令牌已生成,正在提交表单...`);
143164
unsafeWindow.submit_button.click();
144165
observer.disconnect(); // 任务完成,停止监听
145166
}
146167
}
147168
}).observe(cf, { attributes: true, attributeFilter: ['value'] });
148169
}
149170
} catch (error) {
150-
console.error('Error solving CAPTCHA:', error);
171+
console.error('[VPS续期脚本] 处理验证码时发生错误:', error);
151172
}
152173
})();
153174
}

0 commit comments

Comments
 (0)