paul_guo
小狐狸
小狐狸
  • UID45016
  • 注册日期2014-03-13
  • 最后登录2024-04-11
  • 发帖数44
  • 经验52枚
  • 威望0点
  • 贡献值46点
  • 好评度1点
阅读:549回复:0

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

楼主#
更多 发布于: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();
游客

返回顶部