gpt4 book ai didi

javascript - 我正在尝试使用 javascript 在 WhatsApp 上发送短信?

转载 作者:搜寻专家 更新时间:2023-11-01 04:44:00 24 4
gpt4 key购买 nike

我正在尝试在 chrome 上的 whatsapp 网络版上发送短信。( www.web.whatsapp.com )

这是代码:

document.getElementsByClassName("input")[1].innerHTML="This message was written via JS script! ";

var input = document.getElementsByClassName("icon btn-icon icon-send");
input[0].click();

但问题是,最初当没有文本时,输入框看起来像这样: enter image description here

只有当我实际写一些文本时,它才会变成这样:

enter image description here

只有现在我的脚本才能工作,因为它需要 Send text button

我尝试使用 Jquery 代码通过以下函数在 $('.input) 处模拟按键:

function pressKey() {
var e = jQuery.Event("keypress");
e.which = 32; // # space
$(".input").trigger(e)[1];
e.which = 91;
$(".input").trigger(e)[1];
e.which = 32; // # space
$(".input").trigger(e)[1];
e.which = 32; // # space
$(".input").trigger(e)[1];

}

没用。

如何通过脚本获取Send text按钮?

Here is the screen recording :

最佳答案

所有选项都不适合我。我就是这么做的。

function sendMessage(message) {
var evt = new Event('input', {
bubbles: true
});

var input = document.querySelector("div.input");
input.innerHTML = message;
input.dispatchEvent(evt);

document.querySelector(".icon-send").click();
}

关于javascript - 我正在尝试使用 javascript 在 WhatsApp 上发送短信?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28118268/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com