我想编写一个 Chrome 扩展程序,可以使用 Skype 网页版 ( https://web.skype.com/en/ ) 发送消息。我可以获取文本区域中的文本,但无法让它触发 Enter 键。如何存档?
扩展加载正常,并将文本放入输入字段,但它停止了。我还尝试触发更改事件和输入事件。但什么也没发生。
我正在使用等待功能,因为 Skype 需要一段时间才能加载。
我的manifest.json
{ "manifest_version": 2, "name": "SkypeTest", "version": "0.0.1",
"content_scripts": [{"matches": ["https://web.skype.com/*"],
"js": ["jquery-2.1.4.min.js", "skypeTest.js"]}]}
我的 skypeTest.js
;(function() {
var e = jQuery.Event( 'keydown', { which: 13 } );
function init(){
console.log('Script running');
var wait = function() {
var txtArea = $("textarea[name='messageInput']");
if (txtArea.is(':visible')) {
clearTimeout(waiting);
txtArea.val('Hello Skype');
txtArea.trigger('focus').trigger(e);
}
};
var waiting = setInterval(wait, 5000);
}
init();
})();
这是输入字段
<textarea tabindex="10010" maxlength="2000" data-bind="value: messageBody, css: {hide: !isEnabled()},
valueUpdate: ['afterkeydown','propertychange','input'],
event: { keypress: handleKeyPress, keydown: handleKeyDown, input: handleInput,
focus: onFocus, blur: onBlur, paste: onPaste }, hasFocus: chatInputFocus,
l10n_attr: {'placeholder': 'area_text_insertText'}, attr: { 'aria-label': label },
template: { afterRender: handleFocus }" name="messageInput" class="inputField fontSize-p" placeholder="Type a message here"
aria-label="Chat input" style="height: 30px;"></textarea>
最佳答案
由于 Chrome 的安全功能,这似乎是不可能的。 我切换到Electron相反。
关于javascript - 适用于 Skype Web 的 Chrome 扩展程序按键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31364885/