【发布时间】:2015-07-12 06:00:55
【问题描述】:
我想编写一个 Chrome 扩展程序,可以使用 Skype for web (https://web.skype.com/en/) 发送消息。我可以在 textarea 中获取文本,但无法触发 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>
【问题讨论】:
-
谢谢@wOxxOm。我知道 Chrome 中的错误。但这似乎是另一回事。在调试器中,我可以看到分配了正确的 keyCode:n.Event {type: "keydown", which: 13, timeStamp: 1436756197584, jQuery2140713275273796171: true}
标签: javascript google-chrome google-chrome-extension skype