我需要创建一个about:页面,以显示插件选项。我以前见过 ti 做过,但 SDK 中似乎没有允许您这样做的选项。
还有其他方法可以让用户输入about: pagename并访问我的页面吗?
我不希望将所有带有 URL 的选项卡重定向about:pagename
到另一个选项页面。
提前致谢
我需要创建一个about:页面,以显示插件选项。我以前见过 ti 做过,但 SDK 中似乎没有允许您这样做的选项。
还有其他方法可以让用户输入about: pagename并访问我的页面吗?
我不希望将所有带有 URL 的选项卡重定向about:pagename
到另一个选项页面。
提前致谢
这是index.js
使用以下方式开发的无重启插件的文件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();
};
基本上,它注册了一个自定义的 about 页面,当您访问about: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