Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Don't save closed "about:newtab" tabs in undo close history. Only tabs without back/forward history will be removed. You can create Custom Button with this code in initialization.
addEventListener("TabClose", function(e) {
function isNewTabURL(url) {
// See chrome://browser/content/utilityOverlay.js
return url == (window.BROWSER_NEW_TAB_URL || "about:newtab");
}
var tab = e.target;
var browser = tab.linkedBrowser;
if(!isNewTabURL(browser.currentURI.spec))
return;
var sh = browser.sessionHistory;
if(!(sh instanceof Components.interfaces.nsISHistory) || sh.count > 1)
return;
//LOG("Try forget about closed tab");
var ss = (
Components.classes["@mozilla.org/browser/sessionstore;1"]
|| Components.classes["@mozilla.org/suite/sessionstore;1"]
).getService(Components.interfaces.nsISessionStore);
var closedTabs = JSON.parse(ss.getClosedTabData(window));
for(var i = 0, l = closedTabs.length; i < l; ++i) {
var closedTab = closedTabs[i];
var state = closedTab.state;
if(
state.entries.length == 1
&& isNewTabURL(state.entries[state.index - 1].url)
) {
ss.forgetClosedTab(window, i);
//LOG("Forget about closed tab #" + i);
break;
}
}
}, false);
@Drugoy

This comment has been minimized.

Copy link

Drugoy commented Jun 9, 2013

У меня в каждой новой вкладке открывается локальная страница file:///C:/Firefox Release/homepage.html
Я попробовал заменить строку #4 на:
if(browser.currentURI.spec != "about:newtab" && browser.currentURI.spec != "file:///C:/Firefox Release/homepage.html")
и строку #20 на:
&& (state.entries[state.index - 1].url == "about:newtab" || state.entries[state.index - 1].url == "file:///C:/Firefox Release/homepage.html")
но эта страница всё равно оседает в UndoClosedTabs списке, help!

@Infocatcher

This comment has been minimized.

Copy link
Owner Author

Infocatcher commented Jun 10, 2013

Проблема, скорее всего, в пробеле: если выполнить top.opener.content.location.href из Консоли ошибок (или content.location.href из Scratchpad'а), то вместо пробелов будет «%20».

Обновил, теперь проще вносить изменения и будет работать для ссылок, заданных в browser.newtab.url.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.