|
阅读:793回复:5
【求助】newtab-aboutconfig.uc.js 在139不能用了
js 来源:https://github.com/xiaoxiaoflood/firefox-scripts/blob/master/chrome/newtab-aboutconfig.uc.js
用途是更改新标签页地址,更新到139之后不兼容了。 // ==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(); |
|
|
1楼#
发布于:2025-07-09 20:45
lindongbin:(function() {完美! |
|
|
2楼#
发布于:2025-07-09 20:08
(function() {
'use strict';
const DEFAULT_NEWTAB_URL = "about:blank";
const prefName = "browser.newtab.url";
if (!Services.prefs.prefHasUserValue(prefName)) {
Services.prefs.setCharPref(prefName, DEFAULT_NEWTAB_URL);
}
const getNewTabUrl = () => Services.prefs.getCharPref(prefName, DEFAULT_NEWTAB_URL);
if (window.BrowserCommands?.openTab) {
const originalOpenTab = BrowserCommands.openTab;
BrowserCommands.openTab = function({ event, url } = {}) {
originalOpenTab.call(this, { event, url: url || getNewTabUrl() });
};
}
if (window.gBrowser?.removeTab) {
const originalRemoveTab = gBrowser.removeTab;
gBrowser.removeTab = function(aTab, aParams = {}) {
const visibleTabs = this.visibleTabs;
if (visibleTabs.length === 1 && visibleTabs[0] === aTab) {
this.addTab(getNewTabUrl(), {
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal()
});
}
return originalRemoveTab.call(this, aTab, aParams);
};
}
})(); |
|
|
|
3楼#
发布于:2025-07-09 08:57
lindongbin:重写一个试试可用,谢谢! 只是有一个问题,我是设置了关闭最后一个标签页不退出FF的,以前的 js 会自动返回自定义主页,而现在是回到默认主页,这个能再改进一下吗? |
|
|
4楼#
发布于:2025-07-08 21:52
重写一个试试
// newtab-url-override.uc.js
(function() {
'use strict';
const DEFAULT_NEWTAB_URL = "about:blank";
const prefName = "browser.newtab.url";
if (!Services.prefs.prefHasUserValue(prefName) &&
Services.prefs.getPrefType(prefName) === Services.prefs.PREF_INVALID) {
Services.prefs.setCharPref(prefName, DEFAULT_NEWTAB_URL);
}
if (window.BrowserCommands && window.BrowserCommands.openTab) {
const originalOpenTab = BrowserCommands.openTab;
BrowserCommands.openTab = function({ event, url } = {}) {
if (!url) {
url = Services.prefs.getCharPref(prefName, DEFAULT_NEWTAB_URL);
}
originalOpenTab.call(this, { event, url });
};
}
})(); |
|
|
|
5楼#
发布于:2025-07-07 20:32
编辑删除
|
|