-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any way to auto-hide the entire sidebar when only one tab is open? #1768
Comments
I don't think this is possible with just CSS code. An element can only be affected by other elements when they are its parents or preceding siblings to those parents and none of those elements seem to change when the tab count changes. A workaround is to use an extension that uses the method windows.update() with the You need an extension that sets a specific window title prefix string when the window has only one tab. Unfortunately I don't know of any extension that uses the property at all so I can't recommend you a popular extension that does what would be required. Once you have such an extension installed you can use some CSS code in the userChrome.css file like this: @-moz-document url("chrome://browser/content/browser.xul") {
#main-window[titlepreface="1 - "] #sidebar-box[sidebarcommand="treestyletab_piro_sakura_ne_jp-sidebar-action"] {
visibility: collapse !important;
}
} I wrote some code for an example extension that puts a window's tab count in the window's title.
var timeBetweenUpdatesInMilliseconds = 200;
var windowPrefixFormat = "%TabCount% - ";
const tabCountRegExp = new RegExp("%TabCount%", "ig");
var blockedWindows = [];
async function delay(timeInMilliseconds) {
return await new Promise((resolve, reject) => setTimeout(resolve, timeInMilliseconds));
}
function requestNewUpdate(windowId, operationInfo = {}) {
let index = blockedWindows.map(window => window.id).indexOf(windowId);
if (index >= 0) {
blockedWindows[index].operationInfo = operationInfo;
blockedWindows[index].invalidated = true;
} else {
let blockedWindow = {
id: windowId,
operationInfo: operationInfo,
invalidated: false,
update: function () {
updateWindowTabCount(blockedWindow.id, blockedWindow.operationInfo);
}
};
blockedWindows.push(blockedWindow);
delay(timeBetweenUpdatesInMilliseconds).then(() => unblockWindow(blockedWindow));
blockedWindow.update();
}
}
function unblockWindow(blockedWindow) {
let index = blockedWindows.indexOf(blockedWindow);
if (index >= 0) {
blockedWindows.splice(index, 1);
}
if (blockedWindow.invalidated) {
blockedWindow.update();
}
}
async function updateWindowTabCount(windowId = null, operationInfo = {}) {
if (windowId || windowId === 0) {
let tabs = await browser.tabs.query({ windowId: windowId });
let tabCount = tabs.length;
try {
if (operationInfo && operationInfo.tabRemoved && operationInfo.tabId && tabs.map(tab => tab.id).indexOf(operationInfo.tabId) >= 0) {
// If the removed tab was selected when it was closed then it will still be in the provided tab list.
tabCount--;
}
} catch (err) { }
if (tabCount < 1)
tabCount = 1;
setWindowPrefix(windowId, tabCount);
} else {
let windows = await browser.windows.getAll({ populate: true });
for (let window of windows) {
setWindowPrefix(window.id, window.tabs.length);
}
}
}
async function setWindowPrefix(windowId, tabCount) {
await browser.windows.update(windowId, { titlePreface: windowPrefixFormat.replace(tabCountRegExp, tabCount + "") });
}
browser.tabs.onCreated.addListener((tab) => requestNewUpdate(tab.windowId));
browser.tabs.onRemoved.addListener(async (tabId, removeInfo) => requestNewUpdate(removeInfo.windowId, { tabId: tabId, tabRemoved: true }));
browser.tabs.onAttached.addListener((tabId, attachInfo) => requestNewUpdate(attachInfo.newWindowId));
browser.tabs.onDetached.addListener((tabId, detachInfo) => requestNewUpdate(detachInfo.oldWindowId));
updateWindowTabCount();
If you create those two files with the names and content I specified you can then load it as a temporary extension in Firefox 58 by opening If your using Firefox Nightly you can install it as a normal extension by opening More info about installing addons Here is a prepared zip file with the content as I specified: Edit: so I logged into addons.mozilla.org and got the extension signed so it could be used with the stable release of Firefox (v58). Here is a copy: Simply drag and drop it on to Firefox addon page Note: The window title prefix won't be cleared immediately when the extension is disabled. Instead the prefix will be cleared when Firefox is restarted. |
Please note that basically this is impossible by regular method in WebExtensions APIs, because methods to opening/closing sidebar are available only for some limited cases: clicked toolbar button, pre-defined keyboard shortcut, and others. "When a tab is closed" is out of allowed range of the API. |
I released the example extension on addons.mozilla.org as Tab Count in Window Title. The code above is more or less version 1.1 and then I added an option page with some customization options for version 2.1. |
Wow, this works great! Thank you very much for taking the time to put together a workaround like this, and for describing it in so much detail. It works as described: the window displays the number of tabs, and the userChrome.css can make use of that to toggle the sidebar. This gives me more space now when I only have one tab open, and I'm also quite liking the number of tabs being shown in the titlebar. Thanks. Should this be closed? |
@piroor Would the WebExtensions API allow for hiding the sidebar in the window created by 'Move to new window'? That would improve this for at least some of my usage if so! |
I close this because this is out of the range of WebExtensions-based extension. |
Hello. I'm running Tree Style Tab 2.4.9 on Firefox Nightly 60.0a1, Windows 10 Pro.
Is there any way to auto-hide the entire sidebar when only one tab is open? This seems like it'd probably be a userChrome.css type thing, but I've looked through the code snippets page and haven't found anything - maybe I'm blind.
Basically, I'd like to just open a new window and have no TST visible. Open a new tab, and TST appears on the left. Close the tab, and TST disappears again. Thanks.
The text was updated successfully, but these errors were encountered: