Last active
December 11, 2015 13:48
-
-
Save Infocatcher/4609543 to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Проблема, скорее всего, в пробеле: если выполнить 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
У меня в каждой новой вкладке открывается локальная страница 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!