Skip to content

Commit cb88ba9

Browse files
authored
fix语法错误
1 parent d9c54f9 commit cb88ba9

File tree

1 file changed

+80
-43
lines changed

1 file changed

+80
-43
lines changed

renew.user.js

Lines changed: 80 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,85 @@
1313
// @supportURL https://github.com/GitHub30/extend-vps-exp
1414
// ==/UserScript==
1515

16-
// Usage:
17-
// 1. Please bookmark https://secure.xserver.ne.jp/xapanel/login/xvps/
18-
// 2. Open the URL everyday
19-
// 3. (option) Save email and password on Login page
20-
21-
// Login
22-
if (location.pathname.startsWith('/xapanel/login/xvps')) {
23-
const memberid = GM_getValue('memberid')
24-
const user_password = GM_getValue('user_password')
25-
if (memberid && user_password && !document.querySelector('.errorMessage')) {
26-
unsafeWindow.memberid.value = memberid
27-
unsafeWindow.user_password.value = user_password
28-
unsafeWindow.loginFunc()
16+
(function() {
17+
'use strict';
18+
19+
// Usage:
20+
// 1. Please bookmark https://secure.xserver.ne.jp/xapanel/login/xvps/
21+
// 2. Open the URL everyday
22+
// 3. (option) Save email and password on Login page
23+
24+
// Login
25+
if (location.pathname.startsWith('/xapanel/login/xvps')) {
26+
const memberid = GM_getValue('memberid');
27+
const user_password = GM_getValue('user_password');
28+
if (memberid && user_password && !document.querySelector('.errorMessage')) {
29+
unsafeWindow.memberid.value = memberid;
30+
unsafeWindow.user_password.value = user_password;
31+
unsafeWindow.loginFunc();
32+
}
33+
// eslint-disable-next-line no-undef
34+
if (typeof $ !== 'undefined') {
35+
$('#login_area').on('submit', () => {
36+
GM_setValue('memberid', unsafeWindow.memberid.value);
37+
GM_setValue('user_password', unsafeWindow.user_password.value);
38+
});
39+
}
40+
}
41+
42+
// Check expiration date
43+
if (location.pathname.startsWith('/xapanel/xvps/index')) {
44+
const tomorrow = new Date(Date.now() + 864e5).toLocaleDateString('sv');
45+
const expireDate = document.querySelector('tr:has(.freeServerIco) .contract__term')?.textContent;
46+
if (expireDate === tomorrow) {
47+
const href = document.querySelector('tr:has(.freeServerIco) a[href^="/xapanel/xvps/server/detail?id="]').href;
48+
location.href = href.replace('detail?id', 'freevps/extend/index?id_vps');
49+
}
50+
}
51+
52+
// Extend expiration date
53+
if (location.pathname.startsWith('/xapanel/xvps/server/freevps/extend/index')) {
54+
const extendButton = document.querySelector('[formaction="/xapanel/xvps/server/freevps/extend/conf"]');
55+
if (extendButton) {
56+
extendButton.click();
57+
}
2958
}
30-
// eslint-disable-next-line no-undef
31-
$('#login_area').on('submit', () => {
32-
GM_setValue('memberid', unsafeWindow.memberid.value)
33-
GM_setValue('user_password', unsafeWindow.user_password.value)
34-
})
35-
}
36-
37-
// Check expiration date
38-
if (location.pathname.startsWith('/xapanel/xvps/index')) {
39-
const tomorrow = new Date(Date.now() + 864e5).toLocaleDateString('sv')
40-
const expireDate = document.querySelector('tr:has(.freeServerIco) .contract__term')?.textContent
41-
if (expireDate === tomorrow) {
42-
const href = document.querySelector('tr:has(.freeServerIco) a[href^="/xapanel/xvps/server/detail?id="]').href
43-
location = href.replace('detail?id', 'freevps/extend/index?id_vps')
59+
60+
// Solve CAPTCHA
61+
// This part is wrapped in an async IIFE to use 'await'
62+
if ((location.pathname.startsWith('/xapanel/xvps/server/freevps/extend/conf') || location.pathname.startsWith('/xapanel/xvps/server/freevps/extend/do')) && unsafeWindow.submit_button) {
63+
(async function() {
64+
try {
65+
const img = document.querySelector('img[src^="data:"]');
66+
if (!img) return;
67+
68+
const body = img.src;
69+
// Use await to fetch the CAPTCHA solution
70+
const code = await fetch('https://captcha-120546510085.asia-northeast1.run.app', { method: 'POST', body }).then(r => r.text());
71+
72+
const input = document.querySelector('[placeholder="上の画像の数字を入力"]');
73+
if (input) {
74+
input.value = code;
75+
}
76+
77+
const cf = document.querySelector('.cf-turnstile [name=cf-turnstile-response]');
78+
if (cf) {
79+
if (cf.value) {
80+
unsafeWindow.submit_button.click();
81+
}
82+
// Observe for the value change and then click
83+
new MutationObserver((mutationsList, observer) => {
84+
for(const mutation of mutationsList) {
85+
if (mutation.type === 'attributes' && mutation.attributeName === 'value' && cf.value) {
86+
unsafeWindow.submit_button.click();
87+
observer.disconnect(); // Stop observing once clicked
88+
}
89+
}
90+
}).observe(cf, { attributes: true, attributeFilter: ['value'] });
91+
}
92+
} catch (error) {
93+
console.error('Error solving CAPTCHA:', error);
94+
}
95+
})();
4496
}
45-
}
46-
47-
// Extend expiration date
48-
if (location.pathname.startsWith('/xapanel/xvps/server/freevps/extend/index')) {
49-
document.querySelector('[formaction="/xapanel/xvps/server/freevps/extend/conf"]').click()
50-
}
51-
52-
// Solve CAPTCHA
53-
if ((location.pathname.startsWith('/xapanel/xvps/server/freevps/extend/conf') || location.pathname.startsWith('/xapanel/xvps/server/freevps/extend/do')) && unsafeWindow.submit_button) {
54-
const body = document.querySelector('img[src^="data:"]').src
55-
const code = await fetch('https://captcha-120546510085.asia-northeast1.run.app', { method: 'POST', body }).then(r => r.text())
56-
document.querySelector('[placeholder="上の画像の数字を入力"]').value = code
57-
const cf = document.querySelector('.cf-turnstile [name=cf-turnstile-response]')
58-
if (cf.value) unsafeWindow.submit_button.click()
59-
new MutationObserver(() => unsafeWindow.submit_button.click()).observe(cf, { attributes: true, attributeFilter: ['value'] })
60-
}
97+
})();

0 commit comments

Comments
 (0)