mirror of
https://github.com/foxhui/WebAI2API.git
synced 2026-06-16 21:03:59 +08:00
fix: 修复带换行符的提示词触发回车导致提前发送的问题 (closes #2)
This commit is contained in:
@@ -169,6 +169,26 @@ export async function humanType(page, target, text) {
|
||||
// 短文本:保持拟人化逐字输入
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
const char = text[i];
|
||||
const nextChar = text[i + 1];
|
||||
|
||||
// 处理换行符 (避免触发发送)
|
||||
if (char === '\r' && nextChar === '\n') {
|
||||
// Windows 换行符 (\r\n)
|
||||
await page.keyboard.down('Shift');
|
||||
await page.keyboard.press('Enter');
|
||||
await page.keyboard.up('Shift');
|
||||
i++; // 跳过 \n
|
||||
await sleep(30, 100);
|
||||
continue;
|
||||
} else if (char === '\n' || char === '\r') {
|
||||
// Unix/Mac 换行符 (\n 或 \r)
|
||||
await page.keyboard.down('Shift');
|
||||
await page.keyboard.press('Enter');
|
||||
await page.keyboard.up('Shift');
|
||||
await sleep(30, 100);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 模拟错字 (5% 概率)
|
||||
if (Math.random() < 0.05) {
|
||||
await page.keyboard.type('x', { delay: random(50, 150) });
|
||||
|
||||
Reference in New Issue
Block a user