English 中文(简体)
延期:储存数据
原标题:Firefox Extension : Store Addon Data

我正在扩大火ox延伸,使用户能够rag积和 drop。 现在,如果用户关闭申请或重新上页,我就希望恢复他所做的最后活动。

Example : User moves a box from point X to Y.
There can be many more boxes as well.

现在,在网页重载或应用程序启动之后,如果用户在网上添加,我想箱的位置是Y。 因此,如果我使用火焰偏好物,或者还有其他更好的方式这样做。

最佳回答

Nickolay Ponomarev向我建议,采用以下办法可是一个很好的选择:

  • Annotation Service
  • SQLite DB

现在我计划使用数据库。

问题回答

我写了一封信“从一个矿址获得图书标识”的延伸版。 我在当地将图书标识数据作为JSON储存在用户简介目录中的一份文本档案中,如果簿记服务倒塌的话。

我为拯救JSON书记的职能是:

/**
 * Stores bookmarks JSON to local persistence asynchronously.
 *
 * @param bookmarksJson The JSON to store
 * @param fnSuccess The function to call upon success
 * @param fnError The function to call upon error
 */
RyeboxChrome.saveBookmarkJson = function(bookmarksJson, fnSuccess, fnError) {
    var cu = Components.utils;
    cu.import("resource://gre/modules/NetUtil.jsm");
    cu.import("resource://gre/modules/FileUtils.jsm");

    var bookmarksJsonFile = RyeboxChrome.getOrCreateStorageDirectory();
    bookmarksJsonFile.append("bookmarks.txt");

    // You can also optionally pass a flags parameter here. It defaults to
    // FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE;
    var ostream = FileUtils.openSafeFileOutputStream(bookmarksJsonFile);

    var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
    converter.charset = "UTF-8";
    var istream = converter.convertToInputStream(bookmarksJson);

    NetUtil.asyncCopy(istream, ostream, function(status) {
        if ( !Components.isSuccessCode(status) && typeof(fnError) ===  function  ) {
            fnError();
        } else if ( typeof(fnSuccess) ===  function  ) {
            fnSuccess();
        }
        return;
    });
};

阅读数据的功能是:

/**
* Reads bookmarks JSON from local persistence asynchronously.
*
* @param fnSuccess Function to call when successful. The bookmarks JSON will
* be passed to this function.
*
* @param fnError Function to call upon failure.
*/
RyeboxChrome.getBookmarksJson = function(fnSuccess, fnError) {

    Components.utils.import("resource://gre/modules/NetUtil.jsm");

    var bookmarksJsonFile = RyeboxChrome.getOrCreateStorageDirectory();
    bookmarksJsonFile.append("bookmarks.txt");

    NetUtil.asyncFetch(bookmarksJsonFile, function(inputStream, status) {
        if (!Components.isSuccessCode(status) && typeof(fnError) ===  function  ) {
            fnError();
        } else if ( typeof(fnSuccess) ===  function  ){
            var data = NetUtil.readInputStreamToString(inputStream, inputStream.available());
            fnSuccess(data);
        }
    });
};

最后,我的领馆职能是:

/**
 * Storage of data is done in a Ryebox directory within the user s profile
 * directory.
 */
RyeboxChrome.getOrCreateStorageDirectory = function() {

    var ci = Components.interfaces;

    let directoryService = Components.classes["@mozilla.org/file/directory_service;1"].getService(ci.nsIProperties);

    // Reference to the user s profile directory
    let localDir = directoryService.get("ProfD", ci.nsIFile);

    localDir.append("Ryebox");

    if (!localDir.exists() || !localDir.isDirectory()) {
        localDir.create(ci.nsIFile.DIRECTORY_TYPE, 0774);
    }

    return localDir;
};




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jQuery block moving

I wanna move a div block to the top, so I coded like this: CSS part: .movingPart{ margin-top:80px; } jQuery part: $(document).ready(function() { $( #btn ).click(function() { $( .movingPart )....

Private FireFox plugin

I m looking at getting a FireFox plugin developed - but is it possible to create a plugin that is for private use only, so only those I share it with have it and not open to the masses? Need this for ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Cross-browser development

I m developing a web application for a new service, starting from Firefox 3.5. The interface design is tableless, only using divs + CSS & performance-blessed practices. Now, while being ...

Cross browser way of setting IFrame to "about:blank"?

Does anybody know a proper, cross-browser way to "empty" an IFrame? Is "about:blank" recognized without error across all browsers? Is it valid to give an IFrame an empty src?

热门标签