Undo Close Tab
Buttons
-
This button allows you to undo the closing of the most recently closed tab (via left click) view a list of recently closed tabs (via right click) and re-open all recently closed tabs (via middle click).
Future plans:
- Add a checkbox dialogue which allows you to select multiple closed tabs from the list and then "remove all checked" (from the list) or "restore all checked" (in new tabs).
- Maybe add a list item to allow user to set "browser.sessionstore.max_tabs_undo" (i.e. the max number of closed tabs to be remembered) via a prompt.
Behavior
| Action | Behavior |
|---|---|
| Re-opens the last closed tab. | |
| Re-opens all the recently closed tabs. | |
| Opens list of recently closed tabs. |
รุ่น
รหัส
/*
Left-clicking the button will re-open the last tab closed.
Right-clicking the button will show a list of closed tabs, clicking one of these will restore it.
Middle-clicking the button will restore all the closed tabs in the list.
Rawny ^^
*/Init
var button = this; // ***** START OF USER PREFS ***** // /* MaxUndoPref Key: - If the button cannot retrieve the value of "browser.sessionstore.max_tabs_undo" it will set it to this variables value. MenuPref Key: 0 = Do not show the right click menu at all when there are no recently closed tabs to restore. 1 = Show right click menu regardless, if there are no recently closed tabs the menu will show "No previously closed tabs". button.TooltipPref: changes what is shown in the tooltip for tabs in the recently closed tabs list: 0 = The tab's URL 1 = The tab's title and URL 2 = The tab's title */ var MaxUndoPref = 20; var MenuPref = 1; button.TooltipPref = 1; var enabledimage = "data:image/x-icon;base64,AAABAAEAEBAAAAEAGABoAwAAFgAAACgAAAAQAAAAIAAAAAEAGAAAAAAAQAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgkm+EdkqEdkqEdkqKfFGgkm+EdkqEdkqEdkqKfFGgkm+EdkqEdkqEdkqKfFEAAACsnn+1hG61hG61hG6ShFysnn+1hG61hG61hG6ShFysnn+1hG61hG61hG6ShFwAAAC9sZi9mIG9mIG9mIGajGe9sZi9mIG9mIG9mIGajGe9sZi9mIG9mIG9mIGajGcAAADOw6/FrJTFrJTFrJSgkm/Ow6/FrJTFrJTFrJSgkm/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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAq5unjwAAAQB0Uk5T////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AFP3ByUAAAAYdEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My4zNqnn4iUAAADBSURBVChTJY/RcoMwDATdmECaQNxikGWh1hDZ//+Jimjv7VYzmlunigksU5wgoaqzxqUwERDDlNRFq4WZMhDlHFcH1uyeAaiIxNlBFSrlJdUicl1dKsK1tbaHsOPmk0MSltZ+7+MwBPLoEIS51Z9ax48v6NCpAWrng/0osdM/AHUf77sgX1cDiRnk+/OG4UHehilmA2MYhseWPRpQYBsvR9mo7/6BrT6OLT/9JZmc2S79M/b+0i0mewLzn+cl4VlV34r9NZVbcMQFAAAAAElFTkSuQmCC"; var imgAll = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC/xhBQAAAwBQTFRFAAAAU1JSb3Bxpm4TnXBSlnqMn4xxrq9P7JIP5Y8s9K8N77Aw3ZNP369v57BR+M8M89Aw+fQJ+vNP+fFxi4qKmZiXkZSvpKeTqKirt7i4nKnLsNXP3bGQ1Lax4s+x+vSRxMLF2djX6e/U5ejw+Pv6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGxumegAAAQB0Uk5T////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AFP3ByUAAAAYdEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My4zNqnn4iUAAACbSURBVChThY1LEoMgDEABtbUooBAVWi2xcv8rWuLooqu+mZDwJh+2ZwKqWmGgcmc5ZqmVVFqqUyyyl53t8jufHUtj4yc6vVwju5IuOfm+dgRtrIvOmqOFlrb9ozVNY+50JwuAorzV81QAQBYBgvdj2U7j03uAwJCnDAyAOa0cWfUigWKglLxgPG0EiEoQnK3Hf1vDASKd/eG/+AIc9XB759IalAAAAABJRU5ErkJggg=="; // ***** VARS ***** // var r_ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore); // ***** POPULATES THE CONTEXT MENU WITH THE CLOSED TABS LIST ***** // this.populateUndoMenu = function(aNode) { // remove existing menu items while (aNode.hasChildNodes()) aNode.removeChild(aNode.firstChild); // get closed-tabs from nsSessionStore var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore); // return if no restorable tabs if (ss.getClosedTabCount(window) == 0) { aNode.appendChild(document.createElement("menuitem")); aNode.firstChild.setAttribute("label", "No previously closed tabs"); aNode.firstChild.setAttribute("disabled", "true"); return; } // populate menu var undoItems = eval("(" + ss.getClosedTabData(window) + ")"); for(var i = 0; i < undoItems.length; i++) { var m = aNode.appendChild(document.createElement("menuitem")); m.setAttribute("class", "menuitem-iconic bookmark-item"); m.setAttribute("label", undoItems[i].title); m.setAttribute("value", i); var url = GetURL(undoItems[i]); if (button.TooltipPref == 0) { m.tooltipText = url; } else { if (button.TooltipPref == 1) { m.tooltipText = undoItems[i].title+" - "+url; } else { m.tooltipText = undoItems[i].title; } } m.setAttribute("oncommand", "undoCloseTab(" + i + ");"); m.setAttribute("image", undoItems[i].image); } aNode.appendChild(document.createElement("menuseparator")); var mItem = aNode.appendChild(document.createElement("menuitem")); mItem.setAttribute("oncommand", "ClearClosedTabsHistory();"); mItem.setAttribute("label", "Clear closed tabs history"); mItem.setAttribute("image", imgClear); mItem = aNode.appendChild(document.createElement("menuitem")); mItem.setAttribute("oncommand", "OpenAll();"); mItem.setAttribute("label", "Open all in tabs"); mItem.setAttribute("image", imgAll); } // ***** FUNCTIONS ***** // function ReloadIcon() { if (r_ss.getClosedTabCount(window) == 0) { button.tooltipText = "No previously closed tabs"; button.image = disabledimage; } else { button.tooltipText = "Undo close tab"; button.image = enabledimage; } } ClearClosedTabsHistory = function() { try { var maxUndo = gPrefService.getIntPref("browser.sessionstore.max_tabs_undo"); } catch(ex) { var maxUndo = MaxUndoPref; gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", maxUndo); } //clear close tabs history gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", 0); //restore maximum undo history pref gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", maxUndo); ReloadIcon(); } GetURL = function(aTabData) { var history; history = aTabData.state; var activeIndex = (history.index || history.entries.length) - 1; return history.entries[activeIndex].url; history = aTabData.history; return history.getEntryAtIndex(history.index, false).URI.spec; } OpenAll = function() { var undoItems = eval("(" + r_ss.getClosedTabCount(window) + ")"); for(var i = 0; i < undoItems.length; i++) { undoCloseTab(); } } // ***** ADDS THE MENU ITEMS TO THE CONTEXT MENU ***** // const popupID = "cbContext-uctb"; var test = document.getElementById(popupID); if(test) test.parentNode.removeChild(test); var main = document.getElementById("mainPopupSet") var pop = main.appendChild(document.createElement("popup")); pop.id = popupID; pop.setAttribute("onpopupshowing", "document.popupNode.populateUndoMenu(this)"); pop.setAttribute("oncommand", "event.stopPropagation()"); // ***** EXTRA SHOW POPUP FUNCTION ***** // this.showPopup = function(node) { var popup = document.getElementById("cbContext-uctb"); var x = node.boxObject.x; var y = node.boxObject.y + node.boxObject.height + 24; document.popupNode = node; popup.showPopup(node, x, y, "popup", null, null); } // ***** MOUSE/EVENT HANDLING ***** // this.leftclick = function(evt) { if (r_ss.getClosedTabCount(window) > 0) { undoCloseTab(); } }; this.rightclick = function(evt) { if (r_ss.getClosedTabCount(window) > 0 || MenuPref == 1) { this.showPopup(this); } }; this.midclick = function(evt) { OpenAll(); }; function Closed(event) { // Remove event listener window.removeEventListener("focus", ReloadIcon, true); } // ***** INITIALISATION ***** // this.setAttribute("context", popupID); this.setAttribute('onclick', 'custombuttons.gQuot.mHandler(event, this)'); // Calls the Global MouseClick handler gQuot this.setAttribute('ondblclick', 'custombuttons.gQuot.mHandler(event, this)'); window.addEventListener("focus", ReloadIcon, true); window.onclose = Closed; // ***** ATTRIBUTES ***** // this.setAttribute('author','Rawny, Makondo'); this.setAttribute('version','8'); this.setAttribute('homepage', 'http://custombuttons2.com/forum/buttons/buttons-database/undo-close-tab.html'); this.setAttribute('dependency','FF2.0*, FL1.0*, TB2.0*, CB2 2.0.5*'); this.setAttribute('status','Development'); this.setAttribute('public',true);
คู่มือการใช้งาน
Left-clicking the button will re-open the last tab closed. Right-clicking the button will show a list of closed tabs, clicking one of these will restore it. Middle-clicking the button will restore all the closed tabs in the list.
รายละเอียด
Rawny
My buttons
Thankyou for this fantastic button !
I use it daily. The List is an extra bonus !
I think it should be called "Undo Close Tab + list".
I've had the problem of accidentally closing all tabs,
but this css helps to prevent it:
menuitem[label="Close Right Tabs"]
{color: red !important; font-weight: bold !important;}
But for those rare times, it would be helpful to be able to re-open several tabs with one click of a button.
Rating: 5 stars out of 5 stars !
Thankyou SO MUCH makondo and rawny !
Custom Buttons² was not found: find out why...
Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Posted with the theme Pluralism
I have only just installed your button but it certainly does what it says on the tin..
I close the wrong TAB on a regular basis because I am always doing 3 or 4 things at a time. This is a Cool Button.
Custom Buttons² v.3.1.0
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100214 Ubuntu/9.10 (karmic) Firefox/3.5.8
Posted with the theme Pluralism



I would really appreciate if someone could pick up and help with the 'Future'plans here. I'm sooo looking forward to the checkboxes and selective tab reopening.
I have this annoying clumsiness with context menus when instead of 'close right tabs' i click 'close all tabs' and before i can say 'Sharks!", they're all gone. Would be really great for people like me to have that option and be able to re-open a bunch at once.
TIA!
My Styles
Custom Buttons² v.3.0.0
Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8 (.NET CLR 3.5.30729)
Posted with the theme Custom Buttons² Forum Blues