aboutsummaryrefslogtreecommitdiff
path: root/modules/firefox.home/chrome/customNewTab.uc.js
blob: 4c8faca6228bc2a10747b3c9163dc9351c4a5544 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// ==UserScript==
// @name                 Custom New Tab
// @version              1.0
// @description          Load a custom link or local file, instead of the default new tab page
// @startup              UC.customNewTab.updateNewTabURL()
// @shutdown             UC.customNewTab.destroy();
// ==/UserScript==

(() => {
  // Managed in about:config
  const NEWTAB_URL_PREF = 'browser.newtab.url'

  console.log('-------------------------------------------');
  console.log('-------------------------------------------');
  console.log('-------------------------------------------');

  if (!AboutNewTab) {
    globalThis.AboutNewTab = ChromeUtils.import('resource:///modules/AboutNewTab.jsm').AboutNewTab;
  }

  const module = {
    updateNewTabURL: () => {
      const newTabUrl = xPref.get(NEWTAB_URL_PREF) || 'about:blank';
      if (AboutNewTab.newTabURL === newTabUrl) return;

      AboutNewTab.newTabURL = newTabUrl;
      console.log('Updated new tab url to', newTabUrl);
    },

    init() {
      console.log('-------------------------------------------');
      console.log('init new tab');
      console.log('-------------------------------------------');

      module.updateNewTabURL();
      Services.obs.addObserver(module.updateNewTabURL, 'newtab-url-changed');
    },
    destroy() {
      Services.obs.removeObserver(module.updateNewTabURL, 'newtab-url-changed');
    },
  };

  module.init();

  UC.customNewTab = module;
})();