• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Jaeger
V2EX  ›  程序员

前端大佬们,请教个 JS 模拟输入的问题

  •  
  •   Jaeger · May 31, 2024 · 2498 views
    This topic created in 896 days ago, the information mentioned may be changed or developed.

    https://i.imgur.com/YHtbAau.png

    https://kimi.moonshot.cn/

    我想写个 JS 脚本用于模拟在 Kimi 提问界面自动输入问题,方便自己平时快捷提问,但是发现搞不定,求助各位大佬帮助。

    它的输入框不是 input 或者 textarea ,类似下面的常规模拟输入代码对它来说无用:

    // 查找输入框
    var inputElement = document.querySelector('textarea');
    
    // 设置输入框的值
    inputElement.value = "Hello, World!";
    
    // 创建并触发 input 事件
    var event = new Event('input', {
    bubbles: true,
    cancelable: true,
    });
    inputElement.dispatchEvent(event);
    
    // 创建并触发 change 事件
    var changeEvent = new Event('change', {
    bubbles: true,
    cancelable: true,
    });
    inputElement.dispatchEvent(changeEvent);
    
    11 replies  •  2024-06-01 15:12:10 +08:00
    chenliangngng
    chenliangngng
    May 31, 2024
    1
    直接抓请求吧
    4BVL25L90W260T9U
    4BVL25L90W260T9U
    May 31, 2024
    2
    你的了解下啥是 synthetic event
    JoryJoestar
    JoryJoestar
    May 31, 2024
    3
    它用的这个 contenteditable API ,直接可以在元素上修改文字的。你不想抓请求的话,你获取这个 DOM ,innerText 就行了
    Daotin
    Daotin
    May 31, 2024
    4
    自己用输入框为啥不行?
    JoryJoestar
    JoryJoestar
    May 31, 2024
    5
    @JoryJoestar 改是改了,但提交的时候不行,他是输入到它的子元素 span 里面的,你再看看吧
    nulIptr
    nulIptr
    May 31, 2024
    6
    kimi 个人版也有个免费的 api 调用额度。。。不如直接调接口。。。
    idealist
    idealist
    May 31, 2024
    7
    document.querySelector('[contenteditable="true"]').innerHTML = '问题 xxxxxxxxxx'
    renmu
    renmu
    May 31, 2024 via Android
    8
    github 有 kimi api 模拟
    ImGroot
    ImGroot
    May 31, 2024
    9
    看了下 kimi 是用一个 contenteditable 的 div 做了一个输入框, element.value 是 input 元素的属性,要给 div 赋值用 innerText 试试?
    Jaeger
    Jaeger
    OP
    May 31, 2024
    10
    @idealist @ImGroot 大佬牛逼,有效果,但目前只成功了一半,我再研究研究,操作之后页面就报错了,无法提交内容
    e2k
    e2k
    Jun 1, 2024
    11
    点击那个盒子形状的图标 可以添加常用预设进去
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   951 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 60ms · UTC 19:47 · PVG 03:47 · LAX 11:47 · JFK 14:47
    ♥ Do have faith in what you're doing.