gpt4 book ai didi

firefox - 如何在 options.xul 中使用 oncommand 以调用 bootstrap.js 中的函数?

转载 作者:行者123 更新时间:2023-12-04 05:01:28 25 4
gpt4 key购买 nike

我试图从 bootstrap.js 文件调用 changePassword() 方法,但我不知道如何..
Bootstrap.js 位于项目文件夹的根目录,options.xul 位于 ./chrome/content/

<setting type="control" title="&passwordBtn;">
<button label="&passwordBtn;" oncommand="changePassword();"/>
</setting>

提前致谢! :)

最佳答案

首先,更改您的 options.xul 添加一个 id用于以后选择的属性,它不需要 oncommand属性,所以我们可以删除它。

<setting type="control" title="&passwordBtn;">
<button id="password" label="&passwordBtn;" />
</setting>

然后听首选项面板打开并手动将单击的事件监听器添加到按钮。下面是示例 bootstrap.js
const log = function() { dump(Array.slice(arguments).join(' ') + '\n'); }

const {classes: Cc, interfaces: Ci} = Components;
const OBS = Cc['@mozilla.org/observer-service;1']
.getService(Ci.nsIObserverService);

const myAddonId = 'my_addon_id' // same as install.rdf "<em:id>" tag value

let optionObserver = {
observe: function(subject, topic, data) {
if (topic !== 'addon-options-displayed' || data !== myAddonId) {
return;
}
let document = subject.QueryInterface(Ci.nsIDOMDocument);
let button = document.getElementById('password');
button.addEventListener('command', this.changePassword);
},
changePassword: function(event) {
log('password button clicked!');
// do your stuff...
}
}

let install = function(data, reason) {};
let uninstall = function(data, reason) {};

let startup = function(data, reason) {
OBS.addObserver(optionObserver, 'addon-options-displayed', false);
};

let shutdown = function(data, reason) {
OBS.removeObserver(optionObserver, 'addon-options-displayed', false);
};

关于firefox - 如何在 options.xul 中使用 oncommand 以调用 bootstrap.js 中的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16109372/

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