在 Firefox 工具栏中保存下拉历史记录

发布于 2024-07-05 02:50:22 字数 98 浏览 7 评论 0原文

为了学习,我正在 Firefox 工具栏上进行一些测试,但我找不到任何有关如何在用户个人资料中存储“搜索”下拉列表内容的信息。

有没有关于如何解决这个问题的教程?

I'm doing some testing on Firefox toolbars for the sake of learning and I can't find out any information on how to store the contents of a "search" drop-down inside the user's profile.

Is there any tutorial on how to sort this out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伪心 2024-07-12 02:50:22

由于需要相当长的时间才能得到答案,所以我自己去调查了。
这是我现在所拥有的。 我不是很清楚,但它有效。

假设您有一个像这样,在您的 .xul 上:

<textbox id="search_with_history" />

您现在必须添加一些其他属性来启用历史记录。

<textbox id="search_with_history" type="autocomplete"
    autocompletesearch="form-history"
    autocompletesearchparam="Search-History-Name"
    ontextentered="Search_Change(param);"
    enablehistory="true"
 />

这为您提供了在该文本框中启用历史记录的最低限度。
由于某种原因,这就是我的无知所在,onTextEntered 事件函数必须有一个名为“param”的参数。 我尝试了“事件”,但没有成功。
但仅靠这一点是行不通的。 必须添加一些 JavaScript 来帮助完成这项工作。

// This is the interface to store the history
const HistoryObject = Components.classes["@mozilla.org/satchel/form-history;1"]
    .getService(
        Components.interfaces.nsIFormHistory2 || Components.interfaces.nsIFormHistory
    );
// The above line was broken into 4 for clearness.
// If you encounter problems please use only one line.

// This function is the one called upon the event of pressing <enter>
// on the text box
function Search_Change(event) {
    var terms = document.getElementById('search_with_history').value;
    HistoryObject.addEntry('Search-History-Name', terms);
}

这是让历史继续下去的绝对最低限度。

Since it's taking quite a bit to get an answer I went and investigate it myself.
Here is what I've got now. Not all is clear to me but it works.

Let's assume you have a <textbox> like this, on your .xul:

<textbox id="search_with_history" />

You now have to add some other attributes to enable history.

<textbox id="search_with_history" type="autocomplete"
    autocompletesearch="form-history"
    autocompletesearchparam="Search-History-Name"
    ontextentered="Search_Change(param);"
    enablehistory="true"
 />

This gives you the minimum to enable a history on that textbox.
For some reason, and here is where my ignorance shows, the onTextEntered event function has to have the param to it called "param". I tried "event" and it didn't work.
But that alone will not do work by itself. One has to add some Javascript to help with the job.

// This is the interface to store the history
const HistoryObject = Components.classes["@mozilla.org/satchel/form-history;1"]
    .getService(
        Components.interfaces.nsIFormHistory2 || Components.interfaces.nsIFormHistory
    );
// The above line was broken into 4 for clearness.
// If you encounter problems please use only one line.

// This function is the one called upon the event of pressing <enter>
// on the text box
function Search_Change(event) {
    var terms = document.getElementById('search_with_history').value;
    HistoryObject.addEntry('Search-History-Name', terms);
}

This is the absolute minimum to get a history going on.

寂寞清仓 2024-07-12 02:50:22

古斯塔沃,
我想做同样的事情 - 我找到了一个答案 此处位于 Mozilla 支持论坛。 (编辑:我出于兴趣而想保存我的搜索历史记录,而不是因为我想了解 Firefox 工具栏的工作原理,如您所说。)

基本上,该数据存储在名为 formhistory.sqlite 的 sqlite 数据库文件中(在您的 Firefox 中)配置文件目录)。 您可以使用 Firefox 扩展 SQLite Manager 检索和导出数据: https://addons.mozilla .org/firefox/addon/5817

您可以将其导出为 CSV(逗号分隔值)文件,并使用 Excel 或其他软件打开它。

这样做的另一个好处是,如果您对这些数据感兴趣的话,还可以保存您在网站上其他表单/字段(例如 Google 上的搜索字段等)中输入的数据的历史记录。

Gustavo,
I wanted to do the same thing - I found an answer here on the Mozilla support forums. (Edit: I wanted to save my search history out of interest, not because I wanted to learn how the Firefox toolbars work, as you said.)

Basically, that data is stored in a sqlite database file called formhistory.sqlite (in your Firefox profile directory). You can use the Firefox extension SQLite Manager to retrieve and export the data: https://addons.mozilla.org/firefox/addon/5817

You can export it as a CSV (comma- separated values) file and open it with Excel or other software.

This has the added benefit of also saving the history of data you've entered into other forms/fields on sites, such as the Search field on Google, etc, if this data is of interest to you.

梦里兽 2024-07-12 02:50:22

Gustavo 的解决方案很好,但是 document.getElemenById('search_with_history').value; 在 getElementById 中缺少“t”

Gustavo's solution is good, but document.getElemenById('search_with_history').value; is missing a 't' in getElementById

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文