Firefox Addon SDK - 如何创建about:页面 [英] Firefox Addon SDK - How to create an about: page

查看:189
本文介绍了Firefox Addon SDK - 如何创建about:页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个 about:页面,以显示附加选项。我曾经见过ti,但似乎在SDK中没有选择,可以让你做到这一点。



是否有另一种方式,我可以让用户输入 about: pagename 并进入我的页面?



我不希望将所有标签重定向到 about:pagename 到另一个选项页面。



预先感谢

jpm index.js 文件c code code code code code code code code code code $ ;

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

// globals
var factory;
const aboutPage_description ='这是我关于页面的习惯';
const aboutPage_id ='6c098a80-9e13-11e5-a837-0800200c9a66'; //确保你从https://www.famkruithof.net/uuid/uuidgen生成一个唯一的ID $ b $ const const aboutPage_word ='foobar';
const aboutPage_page = Services.io.newChannel('data:text / html,hi这是导航到about:foobar'时显示的页面,null,null);

函数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){
返回Ci.nsIAboutModule.ALLOW_SCRIPT;
},

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

函数工厂(组件){
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();
};

基本上它会注册一个自定义的关于将在您访问时加载的页面:foobar的。加载的页面只是一行文本。



这是这样的:
$ b



你可以在这里看到一个有效的例子: https://github.com/matagus/about-foobar-addon


I need to create an about: page, to display addon options. I have seen ti done before, but there seems to be no option in the SDK that allows you to do that.

Is there another way I could let users type about:pagename and get to my page?

I would prefer not to redirect all tabs with a URL of about:pagename to another options page.

Thanks in advance

解决方案

This is the index.js file for a restartless add-on developed using jpm:

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();
};

Basically it registers a custom about page that will be loaded when you access about:foobar. The loaded page is just a line of text.

This is how it looks like:

You can see a working example here: https://github.com/matagus/about-foobar-addon

这篇关于Firefox Addon SDK - 如何创建about:页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆