gpt4 book ai didi

javascript - 访问热键对象中的选定文本

转载 作者:行者123 更新时间:2023-11-30 17:51:46 24 4
gpt4 key购买 nike

是否可以在 Hotkey 范围内抓取用户选择的文本?
Addon/lib/main.js 中定义:

var showHotKey = Hotkey({
combo: "accel-f1",
onPress: function() {
Addon.saveText(window.getSelection().toString());
}
});

错误..

error: Addon: An exception occurred.
ReferenceError: window is not defined
resource://org/Addon/lib/main.js 14
Traceback (most recent call last):
File "resource://gre/modules/commonjs/sdk/keyboard/observer.js", line 39, in handleEvent
this._emit(event.type, event, event.target.ownerDocument.defaultView);
File "resource://gre/modules/commonjs/sdk/deprecated/events.js", line 123, in _emit
return this._emitOnObject.apply(this, args);
File "resource://gre/modules/commonjs/sdk/deprecated/events.js", line 153, in _emitOnObject
listener.apply(targetObj, params);
File "resource://gre/modules/commonjs/sdk/keyboard/hotkeys.js", line 103, in onKeypress
hotkey();
File "resource://org/Addon/lib/main.js", line 14, in showHotKey<.onPress
Addon.saveText(window.getSelection().toString());

最佳答案

是的,最简单的方法是使用 selection模块。

var { Hotkey } = require("sdk/hotkeys");
var selection = require("sdk/selection");

var showHotKey = Hotkey({
combo: "accel-f1",
onPress: function() {
console.error(selection.text);
}
});

如果您需要更复杂的东西,请查看 tabs.activeTab.attach() ,其中有一个示例展示了一般情况下如何与事件选项卡进行交互。

关于javascript - 访问热键对象中的选定文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18861049/

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