【发布时间】:2020-03-03 20:49:14
【问题描述】:
我正在尝试通过 Greasemonkey for Firefox 向聊天室提交消息。网页上没有按钮,消息必须用回车键发送。检查聊天输入字段,出现:
<input type="text" id="chatcli" placeholder="type chat message here" onkeyup="if(event.keyCode == 13) ChatClient.sendLine();">
我可以使用document.getElementById('chatcli').value = "/bot command here"+x 编辑文本框,但不知道如何实际发送。
我注意到,如果我在控制台中输入ChatClient.sendLine();,消息就会发送。我尝试将该代码放入我的 Greasemonkey 脚本中,但没有成功。我也试过document.ChatClient.sendLine();,没有。
必须有一种方法可以将控制台命令发送到网页。我错过了什么? 如果有人能指出我正确的方向,我将不胜感激。
【问题讨论】:
-
如果在沙箱中运行,显式引用窗口变量:
window.ChatClient.sendLine()(或unsafeWindow.ChatClient.sendLine(),不确定需要哪个),或者将代码注入 DOM,或者禁用沙盒,其中之一可能会工作 -
unsafeWindow.ChatClient.sendLine()工作。谢谢! @CertainPerformance
标签: javascript chat bots greasemonkey chatbot