经过一番询问,我们现在知道您想要的是: 确保每当用户打开一个新选项卡(即用户以空白选项卡打开的选项卡,而不是打开的选项卡)时都会打开一个特定的 URL由用户点击链接并指定在新选项卡中打开链接):
已经有很多扩展可以做到这一点。我建议你检查他们的代码。就我个人而言,我使用Tab Utilities,但它的功能比您想要的要多得多。
very quick search on Mozilla Add-ons 生成了 New Tab Homepage,它非常小,看起来与您想要的 overlay extension 非常接近。另一方面,自定义新标签看起来正是你想要的。但是,它是一个Restartless/Bootstraped extension,这使得它更加复杂。因此,我将在下面显示New Tab Homepage。
如前所述,New Tab Homepage 是一个覆盖扩展。我没有很快看到列出的基于附加 SDK 的扩展。因此,这似乎不是您所要求的。
来自New Tab Homepage的代码:
Javascript (chrome/content/tabhomepage.js):
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is New Tab Homepage.
*
* The Initial Developer of the Original Code is
* Ben Basson <ben@basson.at>
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Basson <ben@basson.at>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
var newtabhomepage = {
init: function ()
{
gBrowser.removeEventListener("NewTab", BrowserOpenTab, false);
window.BrowserOpenTab = newtabhomepage.opentab;
// explicitly add new listener
gBrowser.addEventListener("NewTab", newtabhomepage.opentab, false);
newtabhomepage.prefs = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefService);
},
opentab: function (aEvent)
{
// Firefox allows multiple piped homepages, take the first if necessary
var homepage = gHomeButton.getHomePage().split("|")[0];
var newtab = gBrowser.addTab(homepage);
if (newtabhomepage.prefs.getBoolPref("newtabhomepage.selectnewtab"))
{
gBrowser.selectedTab = newtab;
if (gURLBar)
setTimeout(function() {
// if page is about:blank select() works just like focus, two birds one stone
gURLBar.select();
}, 0);
}
if (aEvent)
aEvent.stopPropagation();
return newtab;
}
}
window.addEventListener("load",newtabhomepage.init,false);
要获得您想要的内容,您可以编辑 JavaScript 以将 URL 分配给静态的东西。
XUL 覆盖(chrome/content/tabhomepage.xul):
<?xml version="1.0"?>
<!--
***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is New Tab Homepage.
The Initial Developer of the Original Code is
Ben Basson <ben@basson.at>
Portions created by the Initial Developer are Copyright (C) 2005
the Initial Developer. All Rights Reserved.
Contributor(s):
Ben Basson <ben@basson.at>
Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
***** END LICENSE BLOCK ***** -->
<overlay id="tabhomepageOverlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:nc="http://home.netscape.com/NC-rdf#">
<script type="application/x-javascript"
src="chrome://tabhomepage/content/tabhomepage.js"/>
</overlay>
chrome.manifest:
overlay chrome://browser/content/browser.xul chrome://tabhomepage/content/tabhomepage.xul
content tabhomepage chrome/content/
安装.rdf:
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>{66E978CD-981F-47DF-AC42-E3CF417C1467}</em:id>
<em:version>0.4.3</em:version>
<em:name>New Tab Homepage</em:name>
<em:description>Loads your homepage when you open a new tab.</em:description>
<em:creator>Ben Basson</em:creator>
<em:homepageURL>http://www.cusser.net</em:homepageURL>
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>3.0b2</em:minVersion>
<em:maxVersion>4.0.*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>
偏好 JavaScript(defaults/preferences/tabhomepage.js):
/* Focus newly created tabs */
pref("newtabhomepage.selectnewtab", true);
这就是New Tab Homepage 扩展的全部内容。