|
58 | 58 | * @description 登录页面逻辑:自动填充并保存用户凭据。 |
59 | 59 | */ |
60 | 60 | if (location.pathname.startsWith('/xapanel/login/xvps')) { |
| 61 | + console.log(`[VPS续期脚本] 当前在登录页面。`); |
61 | 62 | const memberid = GM_getValue('memberid'); |
62 | 63 | const user_password = GM_getValue('user_password'); |
63 | 64 |
|
64 | 65 | // 如果存在已保存的凭据且页面没有显示错误消息,则自动填充并登录 |
65 | 66 | if (memberid && user_password && !document.querySelector('.errorMessage')) { |
| 67 | + console.log(`[VPS续期脚本] 发现已保存的凭据,正在尝试自动登录...`); |
66 | 68 | unsafeWindow.memberid.value = memberid; |
67 | 69 | unsafeWindow.user_password.value = user_password; |
68 | 70 | // 调用页面自带的登录函数 |
69 | 71 | unsafeWindow.loginFunc(); |
| 72 | + } else { |
| 73 | + console.log(`[VPS续期脚本] 未发现凭据或页面有错误信息,等待用户手动操作。`); |
70 | 74 | } |
71 | 75 |
|
72 | 76 | // 监听登录表单的提交事件,以便保存用户输入的凭据 |
73 | | - // 确保 jQuery 已加载 |
74 | 77 | if (typeof $ !== 'undefined') { |
75 | 78 | $('#login_area').on('submit', () => { |
76 | 79 | GM_setValue('memberid', unsafeWindow.memberid.value); |
77 | 80 | GM_setValue('user_password', unsafeWindow.user_password.value); |
| 81 | + console.log(`[VPS续期脚本] 已保存新的用户凭据。`); |
78 | 82 | }); |
79 | 83 | } |
80 | 84 | } |
|
86 | 90 | // 计算明天的日期,格式为 YYYY-MM-DD (瑞典时区格式) |
87 | 91 | const tomorrow = new Date(Date.now() + 86400000).toLocaleDateString('sv'); |
88 | 92 | 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}`); |
89 | 97 |
|
90 | 98 | // 如果到期日是明天,则准备续期 |
91 | 99 | if (expireDate === tomorrow) { |
| 100 | + console.log(`[VPS续期脚本] 条件满足:到期日为明天。正在跳转到续期页面...`); |
92 | 101 | const href = document.querySelector('tr:has(.freeServerIco) a[href^="/xapanel/xvps/server/detail?id="]').href; |
93 | 102 | // 跳转到续期页面 |
94 | 103 | location.href = href.replace('detail?id', 'freevps/extend/index?id_vps'); |
| 104 | + } else { |
| 105 | + console.log(`[VPS续期脚本] 条件不满足:无需执行续期操作。`); |
95 | 106 | } |
96 | 107 | } |
97 | 108 |
|
98 | 109 | /** |
99 | 110 | * @description 续期申请页面逻辑:自动点击确认按钮。 |
100 | 111 | */ |
101 | 112 | if (location.pathname.startsWith('/xapanel/xvps/server/freevps/extend/index')) { |
| 113 | + console.log(`[VPS续期脚本] 当前在续期申请页面。`); |
102 | 114 | const extendButton = document.querySelector('[formaction="/xapanel/xvps/server/freevps/extend/conf"]'); |
103 | 115 | if (extendButton) { |
| 116 | + console.log(`[VPS续期脚本] 找到续期按钮,正在点击...`); |
104 | 117 | extendButton.click(); |
| 118 | + } else { |
| 119 | + console.log(`[VPS续期脚本] 未找到续期按钮。`); |
105 | 120 | } |
106 | 121 | } |
107 | 122 |
|
|
111 | 126 | */ |
112 | 127 | if ((location.pathname.startsWith('/xapanel/xvps/server/freevps/extend/conf') || location.pathname.startsWith('/xapanel/xvps/server/freevps/extend/do')) && unsafeWindow.submit_button) { |
113 | 128 | (async function() { |
| 129 | + console.log(`[VPS续期脚本] 当前在验证码页面,开始处理验证码...`); |
114 | 130 | try { |
115 | 131 | const img = document.querySelector('img[src^="data:"]'); |
116 | 132 | if (!img) { |
117 | | - console.log('CAPTCHA image not found.'); |
| 133 | + console.log('[VPS续期脚本] 未找到验证码图片。'); |
118 | 134 | return; |
119 | 135 | } |
| 136 | + console.log('[VPS续期脚本] 已找到验证码图片,正在发送到API进行识别...'); |
120 | 137 |
|
121 | 138 | const body = img.src; |
122 | 139 | // 调用外部API来识别验证码图片 |
123 | 140 | const code = await fetch('https://captcha-120546510085.asia-northeast1.run.app', { method: 'POST', body }).then(r => r.text()); |
| 141 | + console.log(`[VPS续期脚本] API返回验证码: ${code}`); |
124 | 142 |
|
125 | 143 | const input = document.querySelector('[placeholder="上の画像の数字を入力"]'); |
126 | 144 | if (input) { |
127 | 145 | input.value = code; |
| 146 | + console.log(`[VPS续期脚本] 已将验证码填入输入框。`); |
128 | 147 | } |
129 | 148 |
|
130 | 149 | // 处理 Cloudflare Turnstile 人机验证 |
131 | 150 | const cf = document.querySelector('.cf-turnstile [name=cf-turnstile-response]'); |
132 | 151 | if (cf) { |
133 | | - // 如果令牌已经存在,直接点击提交 |
| 152 | + console.log(`[VPS续期脚本] 正在处理 Cloudflare Turnstile...`); |
134 | 153 | if (cf.value) { |
| 154 | + console.log(`[VPS续期脚本] Cloudflare 令牌已存在,直接提交表单。`); |
135 | 155 | unsafeWindow.submit_button.click(); |
136 | 156 | return; |
137 | 157 | } |
138 | | - // 如果令牌尚不存在,则使用 MutationObserver 监听其值的变化 |
| 158 | + console.log(`[VPS续期脚本] Cloudflare 令牌不存在,设置监听器等待生成...`); |
139 | 159 | // 一旦 cf-turnstile-response 的 value 被填充,就立即点击提交按钮 |
140 | 160 | new MutationObserver((mutationsList, observer) => { |
141 | 161 | for(const mutation of mutationsList) { |
142 | 162 | if (mutation.type === 'attributes' && mutation.attributeName === 'value' && cf.value) { |
| 163 | + console.log(`[VPS续期脚本] Cloudflare 令牌已生成,正在提交表单...`); |
143 | 164 | unsafeWindow.submit_button.click(); |
144 | 165 | observer.disconnect(); // 任务完成,停止监听 |
145 | 166 | } |
146 | 167 | } |
147 | 168 | }).observe(cf, { attributes: true, attributeFilter: ['value'] }); |
148 | 169 | } |
149 | 170 | } catch (error) { |
150 | | - console.error('Error solving CAPTCHA:', error); |
| 171 | + console.error('[VPS续期脚本] 处理验证码时发生错误:', error); |
151 | 172 | } |
152 | 173 | })(); |
153 | 174 | } |
|
0 commit comments