Skip to content

Commit

Permalink
Workaround für Bugzilla 1240559 (New Tab Override funktioniert nicht …
Browse files Browse the repository at this point in the history
…in Firefox 44)
  • Loading branch information
cadeyrn committed Jan 19, 2016
1 parent a30cef4 commit 2a862c5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Mozilla decided to remove it (see [bug 1118285](https://bugzilla.mozilla.org/sho
by removing it, Mozilla also introduced a new API to bring this functionality back to life as an add-on. This add-on
allows the user to choose a certain page in a new tab.
### Download
**[Download New Tab Override 2.3](https://addons.mozilla.org/en-US/firefox/addon/new-tab-override/)**
**[Download New Tab Override 2.3.1](https://addons.mozilla.org/en-US/firefox/addon/new-tab-override/)**
Binary file added dist/[email protected]
Binary file not shown.
32 changes: 28 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
const NEW_API_FIREFOX_VERSION = 44;
const ONE_SECOND_IN_MILLISECONDS = 1000;
const URL_CHARS_LIMIT = 2000;

const { PrefsTarget } = require('sdk/preferences/event-target');
const { setInterval, clearInterval } = require('sdk/timers');
const { version } = require('sdk/system/xul-app');
const clipboard = require('sdk/clipboard');
const newTabUrlJsm = require('resource:///modules/NewTabURL.jsm').NewTabURL;
const preferencesService = require('sdk/preferences/service');
const prefsTarget = PrefsTarget({ branchName: 'browser.startup.'});
const simplePrefs = require('sdk/simple-prefs');

const newtaboverride = {
lastClipboardUrl : false,
timer : false,
version : parseFloat(version),

init : function () {
newtaboverride.onPrefChange();
},

override : function (newTabUrl) {
if (this.version < NEW_API_FIREFOX_VERSION) {
require('resource:///modules/NewTabURL.jsm').NewTabURL.override(newTabUrl);
} else {
const { Cc, Ci } = require('chrome');
const aboutNewTabService = Cc['@mozilla.org/browser/aboutnewtab-service;1'].getService(Ci.nsIAboutNewTabService);

aboutNewTabService.newTabURL = newTabUrl;
}
},

reset : function () {
if (this.version < NEW_API_FIREFOX_VERSION) {
require('resource:///modules/NewTabURL.jsm').NewTabURL.reset();
} else {
const { Cc, Ci } = require('chrome');
const aboutNewTabService = Cc['@mozilla.org/browser/aboutnewtab-service;1'].getService(Ci.nsIAboutNewTabService);

aboutNewTabService.resetNewTabURL();
}
},

onPrefChange : function () {
var type = simplePrefs.prefs['type'];
Expand Down Expand Up @@ -53,7 +77,7 @@ const newtaboverride = {
newtaboverride.lastClipboardUrl = false;
}

newTabUrlJsm.override(newTabUrl);
newtaboverride.override(newTabUrl);
},

clipboardAction : function () {
Expand All @@ -68,7 +92,7 @@ const newtaboverride = {
}

if (!newtaboverride.lastClipboardUrl || clipboardContent !== newtaboverride.lastClipboardUrl) {
newTabUrlJsm.override(clipboardContent);
newtaboverride.override(clipboardContent);
newtaboverride.lastClipboardUrl = clipboardContent;
}
},
Expand Down Expand Up @@ -97,6 +121,6 @@ exports.onUnload = function (reason) {
if (reason === 'uninstall' || reason === 'disable') {
clearInterval(newtaboverride.timer);
newtaboverride.lastClipboardUrl = false;
newTabUrlJsm.reset();
newtaboverride.reset();
}
};
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "[email protected]",
"title": "New Tab Override (browser.newtab.url replacement)",
"name": "newtaboverride",
"version": "2.3",
"version": "2.3.1",
"description": "This add-on brings back the ability to change the page which is shown when opening a new tab.",
"main": "index.js",
"author": "Sören Hentzschel (agenedia.com)",
Expand Down

0 comments on commit 2a862c5

Please sign in to comment.