简体   繁体   English

Firefox附加组件:添加具有不同URL和建议的搜索引擎

[英]Firefox-Addon: Add search engine with varying URL and suggestions

my Firefox addon shall add a search engine, that 我的Firefox插件应添加一个搜索引擎,

  • provides suggestions 提供建议
  • gets its search template URL specified on runtime (ie: template URL depends on the preferences of the user) 获取其在运行时指定的搜索模板URL(即:模板URL取决于用户的首选项)

And I don't see a way to do both at the same time. 而且我看不到同时做这两种方法的方法。

I see two options to add a search engine: 我看到两个添加搜索引擎的选项:

addEngineWithDetails() allows me to add a search engine with the template URL. addEngineWithDetails()允许我添加带有模板URL的搜索引擎。 But it does (apparently?) not allow to provide a suggestions URL. 但是(显然吗?)不允许提供建议URL。

addEngine() allows me to add a search engine that is specified in an XML file. addEngine()允许我添加XML文件中指定的搜索引擎。 But if have that file saved locally in my addon directory (eg chrome://example-engine/content/search.xml ), how can I change the template URL on runtime? 但是,如果该文件已本地保存在我的插件目录中(例如chrome://example-engine/content/search.xml ),如何在运行时更改模板URL? And using an online XML is an unsafe options since the internet connection could be broken or bad during the addon install. 而且,使用在线XML是不安全的选择,因为在插件安装期间Internet连接可能断开或损坏。

First fo all, you're right, addEngineWithDetails does not support suggestions. 首先,您是对的, addEngineWithDetails不支持建议。

The way to go would be to use addEngine (and removeEngine ). 要走的路是使用addEngine (和removeEngine )。

As for the "dynamic" part of your question: While I didn't test it, the implementation seems to happily accept data: URIs . 至于您问题的“动态”部分:尽管我没有对其进行测试,但该实现似乎很乐意接受data: URIs So you could: 因此,您可以:

  • Construct a data URI using whatever methods you like (even constructing a full XML DOM and serializing it). 使用您喜欢的任何方法构造数据URI(甚至构造完整的XML DOM并对其进行序列化)。
  • Call addEngine with the data URI. 使用数据URI调用addEngine
  • When the user changes a pref, remove the old engine, and construct a new one. 当用户更改首选项时,请删除旧引擎,然后构造一个新引擎。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM