簡體   English   中英

Firefox插件SDK-如何創建關於:頁面

[英]Firefox Addon SDK - How to create an about: page

我需要創建一個about:頁面,以顯示插件選項。 我以前看過ti,但是在SDK中似乎沒有選擇允許您這樣做。

還有另一種方法可以讓用戶輸入pagename並進入我的頁面嗎?

我不希望將URL: about:pagename所有選項卡重定向到另一個選項頁面。

提前致謝

這是使用jpm開發的無重啟附件的index.js文件:

const { Cc, Ci, Cr, Cu, Cm, components } = require("chrome");

Cm.QueryInterface(Ci.nsIComponentRegistrar);
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");

// globals
var factory;
const aboutPage_description = 'This is my custom about page';
const aboutPage_id = '6c098a80-9e13-11e5-a837-0800200c9a66'; // make sure you generate a unique id from https://www.famkruithof.net/uuid/uuidgen
const aboutPage_word = 'foobar';
const aboutPage_page = Services.io.newChannel('data:text/html,hi this is the page that is shown when navigate to about:foobar', null, null);

function AboutCustom() {};

AboutCustom.prototype = Object.freeze({
    classDescription: aboutPage_description,
    contractID: '@mozilla.org/network/protocol/about;1?what=' + aboutPage_word,
    classID: components.ID('{' + aboutPage_id + '}'),
    QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),

    getURIFlags: function(aURI) {
        return Ci.nsIAboutModule.ALLOW_SCRIPT;
    },

    newChannel: function(aURI) {
        let channel = aboutPage_page;
        channel.originalURI = aURI;
        return channel;
    }
});

function Factory(component) {
    this.createInstance = function(outer, iid) {
        if (outer) {
            throw Cr.NS_ERROR_NO_AGGREGATION;
        }
        return new component();
    };
    this.register = function() {
        Cm.registerFactory(component.prototype.classID, component.prototype.classDescription, component.prototype.contractID, this);
    };
    this.unregister = function() {
        Cm.unregisterFactory(component.prototype.classID, this);
    }
    Object.freeze(this);
    this.register();
}

exports.main = function() {
  factory = new Factory(AboutCustom);
};

exports.onUnload = function(reason) {
  factory.unregister();
};

基本上,它注冊了一個自定義的About頁面,該頁面將在您訪問about:foobar時加載。 加載的頁面只是一行文本。

它是這樣的:

關於:foobar頁面

您可以在這里看到一個有效的示例: https : //github.com/matagus/about-foobar-addon

我認為如果您使用addons-sdk,這是一個更好的解決方案:

信用在這里: https//stackoverflow.com/a/9196046/1038866

var pageMod = require("page-mod");
pageMod.PageMod({
  include: data.url("options.html"),
  ...
});    
var tabs = require("tabs");
tabs.open(data.url("options.html"));

但是還有其他方法。 您可以看一下實現此功能的Scroll to Top插件: https : //addons.mozilla.org/firefox/addon/402816

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM