Bootstrap插件创建选项按钮与任意js

Bootstrap addon create options button with arbitrary js

本文关键字:任意 js 按钮 选项 插件 创建 Bootstrap      更新时间:2023-09-26

我从Bugzilla发现你可以在安装时设置你的选项url。将RDF转换为任意js,它将运行得非常好。唯一的问题是,窗口停用,就好像一个看不见的对话框在它上面打开,无论如何你不能关闭它。

例如

:在我的插件这里:简单的测试用例,在启动时,它只是提醒启动,在插件管理器中,它会显示选项按钮,点击它会做一个notifyObserver,但然后它会进入所有对话模式:GitHub:: Noitidart/PortableTester

你可以用GitHubExtensionInstaller插件直接从repo安装这个插件

代码在my optionsurl:

<em:optionsURL>
    javascript:Components.utils.import('resource://gre/modules/Services.jsm');Services.obs.notifyObservers(window, 'hellothisisyourcaptainspeaking', 'options')
</em:optionsURL>

我想避免进入这个不可见的对话框模式后,点击选项按钮。或者如果我们不能阻止它,我想添加一些代码到optionsurl来退出这个锁定模式。

在这一点上,我已经尝试了这个代码,它没有工作:

        javascript:
        Components.utils.import('resource://gre/modules/Services.jsm');
        Services.obs.notifyObservers(window, 'hellothisisyourcaptainspeaking', 'options');
        var DOMWin =    window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebNavigation).QueryInterface(Components.interfaces.nsIDocShellTreeItem).rootTreeItem.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow);
        var utils = DOMWin.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils);
        utils.leaveModalState();

这可以在这里看到:GitHub:: Noitdart/PortableTester提交显示试图离开这个对话模式

你不能阻止Add-ons Manager打开一个模态对话框。但是,您可以很容易地关闭它,只需将window.close()添加到命令中。这假定你的代码是在模态对话框的上下文中运行的——如果不是,那么Services.wm.getMostRecentWindow(null).close()应该这样做。

但是,我认为在这里使用javascript: URL很尴尬,这种方法将来也可能会中断。您应该考虑使用包含JavaScript文件的最小XUL对话框(没有任何样式表,因此它也是不可见的)。然后,您将在适当的脚本文件中编写代码,而不是将其全部压缩到install.rdf中的一行。