firefox117后失效的newtab-aboutconfig.uc.js

阅读:551回复:0
2023-09-14 12:22
写私信
楼主#
// ==UserScript==
// @name            Restore browser.newtab.url in about:config
// @author          TheRealPSV
// @include         main
// @shutdown        UC.NewTabAboutConfig.destroy();
// @onlyonce
// ==/UserScript==

const { AboutNewTab } = ChromeUtils.import(
  "resource:///modules/AboutNewTab.jsm"
);

UC.NewTabAboutConfig = {
  NEW_TAB_CONFIG_PATH: "browser.newtab.url",
  init: function () {
    //fetch pref if it exists
    this.newTabURL = xPref.get(this.NEW_TAB_CONFIG_PATH);

    //if pref doesn't exist, give it a default value of about:blank
    if (!this.newTabURL) {
      this.newTabURL = "about:blank";
      xPref.set(this.NEW_TAB_CONFIG_PATH, this.newTabURL);
    }

    //set the new tab URL in the browser itself, and add a listener to update it when the config is changed
    try {
      AboutNewTab.newTabURL = this.newTabURL;
      this.prefListener = xPref.addListener(
        this.NEW_TAB_CONFIG_PATH,
        (value) => {
          AboutNewTab.newTabURL = value;
        }
      );
    } catch (e) {
      console.error(e);
    } // Browser Console
  },

  destroy: function () {
    xPref.removeListener(this.NEW_TAB_CONFIG_PATH);
  },
};

UC.NewTabAboutConfig.init();