Lej77 / tab-count-in-window-title

6 stars 1 forks source link

[Request] Make tab count less intrusive #5

Closed protist closed 4 years ago

protist commented 4 years ago

This add-on sounds like a excellent workaround to hide TST when there's a single tab. However, I find that the tab count as a prefix for all windows a bit annoying, because it makes this number more important than the name of the window. For example, in my panel, the tab-count prefix leaves less space for the window title:

Screenshot_20200610_200526

I could think of two different possibilities.

  1. Would it be possible to move the tab count to the end of the window name, instead of the beginning? I'm not sure if that would work; is a suffix version of titlepreface?
  2. Can we just have the prefix/suffix on some windows, e.g. either only those with one tab, or alternatively only those with >1 tab?
Lej77 commented 4 years ago

The title preface is a feature offered by Firefox's extension API and unfortunately there doesn't seem to be a similar property for setting a suffix. You could probably modify a window's title by changing the active tab's title using some injected JavaScript but that has a number of drawbacks:

Your second suggestion of only changing the title preface when there is a single tab is interesting and should certainly be possible. The only question is how such a feature should be implemented. I can think of a couple of alternatives:

protist commented 4 years ago

Thanks @Lej77. That makes sense in your response to the first suggestion.

Regarding the other three options, I guess the greater flexibility the better IMO.

  • A checkbox to only set the title preface for windows with more than 1 tab or some other condition.

I think that this is a bit too restrictive. What if users wanted to do the opposite, i.e. only set the preface for windows with 1 tab?

  • A new placeholder similar to %IfWindowName(True,False)% that checks if there is more than one tab in the current window.

That sounds pretty good to me! I also realised that all of these solutions would allow users to use a shorter string for one/more tabs (e.g. some obscure character), which would only used to match the TST rule.

  • A new more general placeholder that checks if some text matches a regex and resolves to different text depending on if that is true %IfRegexMatch(%TabCount%,1,[One tab],[Many tabs])%

I don't entirely understand this one. Are you saying that if 1 ~ %TabCount%, then show [One tab], else show [Many tabs]? This would be super cool and very powerful, but TBH I'm not sure how hard and complex it would be to code. I'm also not 100% sure in what use cases it would be better than the second option. Although maybe future proofing is also goo.

Lej77 commented 4 years ago

I do indeed mean that if %TabCount% is equal to the text 1 then the text [One tab] should be shown and otherwise the [Many tabs] text should be used. I think this shouldn't be much harder to implement than the simpler placeholder that only checks if there is a single tab. Hopefully this turns out to be correct and I get some time over to actually implement this! I also remember some of the code being a mess so might need to fix that up a bit to implement this but I'm not sure about that.

protist commented 4 years ago

Awesome! That sounds promising. Thank you for the response.

Lej77 commented 4 years ago

I have released a new version of the extension (v5.0) that has a %IfRegexMatch()% placeholder. You could use a title preface like %IfRegexMatch(;%TabCount%;,;1;,, ,)%%IfWindowName(| %WindowName% | ,)%. Then you could use a #main-window[titlepreface^=" "] selector in your userChrome.css file. This exploits the fact that spaces in the preface aren't really visible in a window's title so the title should actually look the same when there is a single tab and when there are many tabs but the css rules should still be applied correctly.

Edit: make sure you are using version 5.3 or later of the extension when you are testing the format I suggested since there was a race condition when the format evaluated to an empty string. The fix for that race condition was released in that version.

Edit 2: using only an empty space for the css rules might cause flickering if the title format is ever evaluated to an empty string since I clear such title prefaces by settings the preface to " " first and then "" to handle some limitations of the WebExtension API.

Edit 3: you can use a zero sized character to apply css rules without changing you window title. So a format like %IfRegexMatch(;%TabCount%;,;1;,,​,)%%IfWindowName(| %WindowName% | ,)% and a rule like #main-window[titlepreface^="​"]. Note that there are invisible extra characters in these!

Otherwise you can of course use any character you want so a format like %IfRegexMatch(;%TabCount%;,;1;,,*,)%%IfWindowName(| %WindowName% | ,)% and a css rule like #main-window[titlepreface^="*"] would work as well.

protist commented 4 years ago

Absolutely brilliant! Thank you! The zero-width character works perfectly!