Skip to content

Commit

Permalink
Rewrite to SDK-based add-on.
Browse files Browse the repository at this point in the history
  • Loading branch information
benbasson committed Aug 29, 2015
1 parent ca34c51 commit daf926d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 111 deletions.
2 changes: 0 additions & 2 deletions src/chrome.manifest

This file was deleted.

47 changes: 0 additions & 47 deletions src/chrome/content/tabhomepage.xul

This file was deleted.

2 changes: 0 additions & 2 deletions src/defaults/preferences/tabhomepage.js

This file was deleted.

61 changes: 26 additions & 35 deletions src/chrome/content/tabhomepage.js → src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* The Initial Developer of the Original Code is
* Ben Basson <[email protected]>
* Portions created by the Initial Developer are Copyright (C) 2005
* Portions created by the Initial Developer are Copyright (C) 2015
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
Expand All @@ -35,40 +35,31 @@
*
* ***** END LICENSE BLOCK ***** */

var newtabhomepage = {
const gprefs = require("sdk/preferences/service");
const newtaburl = require('resource:///modules/NewTabURL.jsm').NewTabURL;

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;
}
// access global startup prefs
var { PrefsTarget } = require("sdk/preferences/event-target");
var target = PrefsTarget({ branchName: "browser.startup."});

}
// set the newtab url preference on startup / install / enable / upgrade
exports.main = function (options, callbacks) {
overrideNewTabPage();
};

// if the homepage is changed, set the new override
target.on("homepage", function () {
overrideNewTabPage();
});

window.addEventListener("load",newtabhomepage.init,false);
// if the add-on is unloaded, revert the override
exports.onUnload = function (reason) {
newtaburl.reset();
};

// overrides the new tab to the (first) homepage
function overrideNewTabPage() {
// Firefox allows multiple piped homepages, take the first if necessary
var homepage = gprefs.getLocalized("browser.startup.homepage", "about:home").split("|")[0];
newtaburl.override(homepage);
}
25 changes: 0 additions & 25 deletions src/install.rdf

This file was deleted.

14 changes: 14 additions & 0 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "{66E978CD-981F-47DF-AC42-E3CF417C1467}",
"title": "New Tab Homepage",
"name": "newtabhomepage",
"version": "0.5.0",
"description": "Loads your homepage when you open a new tab.",
"homepage": "http://www.basson.at/firefox-addons/newtabhomepage",
"author": "Ben Basson",
"engines": {
"firefox": ">=41.0a2"
},
"license": "MPL",
"main": "index.js"
}

0 comments on commit daf926d

Please sign in to comment.