v2p-ks/tx.js
2025-08-31 13:07:06 +08:00

55 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ==Rewrite==
// @name 修改 /withdraw/apply 请求体
// @version 1.0.0
// @description 在 /withdraw/apply 的请求体末尾添加 &verify_type=1
// @author YourName
// @match *://*/*
// @run-at request-body
// ==/Rewrite==
if (typeof $request !== 'undefined' && $request.body) {
// 检查请求的 URL 是否包含目标路径
if ($request.url.indexOf('/withdraw/apply') !== -1) {
// 获取当前的请求体
let body = $request.body;
// 检查请求体是否已经包含 verify_type避免重复添加
if (body.indexOf('verify_type=') === -1) {
// 在请求体末尾添加 &verify_type=1
// 注意:需要根据原始请求体的格式来处理拼接符号(& 或 ?
let newBody;
if (body.length > 0) {
// 如果原请求体不为空,且最后一位不是&,则添加&,否则直接添加
if (body.endsWith('&')) {
newBody = body + 'verify_type=1';
} else if (body.indexOf('?') !== -1 && body.endsWith('?')) {
// 如果请求体是URL编码形式且以?结尾这种情况较少见通常GET参数在URL中POST请求体多是表单编码或JSON
newBody = body + 'verify_type=1';
} else {
// 最常见的情况,原请求体不为空,且没有以&结尾,则添加&后拼接
newBody = body + '&verify_type=1';
}
} else {
// 如果原请求体为空,则直接添加
newBody = 'verify_type=1';
}
// 打印日志,便于调试
console.log(`Original Body: ${body}`);
console.log(`Modified Body: ${newBody}`);
// 完成重写,返回修改后的请求体
$done({ body: newBody });
} else {
// 如果已经存在 verify_type则不进行任何修改
console.log('verify_type already exists in request body. No modification needed.');
$done({});
}
} else {
// 如果不是目标 URL直接放行
$done({});
}
} else {
// 如果没有请求体,直接放行
$done({});
}