Alhadis / Unfuck-Tabstops

Bookmarket to aggressively convert 2-space tabstops on GitHub to real tabs.
ISC License
8 stars 1 forks source link

How to fix tab size in Mozilla browsers #2

Open RealRaven2000 opened 4 years ago

RealRaven2000 commented 4 years ago

I was desperately searching for some method to make my GitHub code (for Thunderbird Add-ons) readable again and found this repo. I require a tab size of 2 because that's what I use in all my source code - and a lot of it is "mixed" so the indentation looks useless with other tab sizes.

Anyway, although I didn't find a solution for myself here, I came up with a very primitive, Mozilla-specific quickfix, which works for me on Waterfox (I switched to WF because Firefox stopped supporting my own legacy add-ons and I haven't got time to convert everything to web extensions).

The solution is just a single rule in userContent.css:

/* adjust tab size in github */
.tab-size[data-tab-size="8"] {
    -moz-tab-size: 2 !important;
}

I bet this rule could be turned into something equally useful on chrome with a GreaseMonkey script or whatever the hip people are using nowadays to tweak web content.

Alhadis commented 4 years ago

Does the current script not work when run as a bookmarklet in Firefox? 🤔

I was desperately searching for some method to make my GitHub code (for Thunderbird Add-ons) readable again

To change the tab-size GitHub uses when displaying source code, there's an unintuitive (and undocumented) hack you can try that involves adding an .editorconfig file with an indent_size field. For example:

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = false
indent_style = tab
indent_size = 4

As stated above, this is a hack. I've been nagging GitHub for years to add a repository setting for changing the default tab-width, but despite having the time to redesign the entire site (twice), they still haven't bothered implementing it. 🙄

Alhadis commented 4 years ago

If you have a moment, I recommend voicing your support at the aforementioned thread and/or submitting a ticket to site support. The only way to get GitHub to listen to their users is when enough of them complain… 😖

(If I sound ticked-off, it's because I am. There's literally no reason they shouldn't add this, and it's not even complicated…)

RealRaven2000 commented 4 years ago

Does the current script not work when run as a bookmarklet in Firefox? thinking

I don't know, I am not using Firefox this much. Just for some browsing task for which Waterfox Classic is too outdated. As long as there is no easy way to get to the passwords it has only limited usefulness to me as a browser.

To change the tab-size GitHub uses when displaying source code, there's an unintuitive (and undocumented) hack you can try that involves adding an .editorconfig file with an indent_size field. For example:

I can try it out, I need it mainly for diffs and viewing code (not so much for editing on the site, I really don't do that)

Alhadis commented 4 years ago

I need it mainly for diffs and viewing code

I don't believe this trick extends to diffs, or to code-blocks in rendered markdown (including comments in PR/issue discussions). I'd report these oversights to GitHub, but I doubt they'd give a damn about fixing it…

I don't know, I am not using Firefox this much

My bad, I should have said *Mozilla. A bad habit of mine is referring to Gecko or Mozilla as "Firefox" (even though I know damn well that the latter refers to a browser, not a rendering engine or some other technology used in Firefox… 😅)

RealRaven2000 commented 4 years ago

I don't know, I am not using Firefox this much

My bad, I should have said *Mozilla. A bad habit of mine is referring to Gecko or Mozilla as "Firefox" (even though I know damn well that the latter refers to a browser, not a rendering engine or some other technology used in Firefox… sweat_smile)

understandable mistake - I used PaleMoon for a while (for the same reason, mainly to use my own Add-ons QuickPasswords, MenuOnTop and ZombieKeys) and then found Waterfox, which is the most up-to-date app supporting legacy Add-ons. Thunderbird is a different kettle of fish, I have invested quite a bit of money so far and we are working on converting my commercial Add-ons to the interim status (mail experiments), with a view of hopefully getting them to work as web extensions next year (for this, I invested 3k so far).

Estimated effort for making web extensions: probably around 8,000$ So I need to seriously raise my user count to make it worth my while.

Alhadis commented 4 years ago

Well, good luck!

Estimated effort for making web extensions: probably around 8,000$

To me, any figure longer than 3 digits sounds exorbitant. 😂 Then again, I'm broke as fuck.

and a lot of it is "mixed" so the indentation looks useless with other tab sizes.

BTW, before I forget, a known limitation of this script is that it (currently) doesn't handle mixed or hanging indents. I intend to fix this eventually — it's more complicated than simple search-and-replace, as it needs to consider physical coordinates of HTML tags (to distinguish a semantic indent from a hanging indent).

This problem is compounded by the fact there's no easy way to retrieve the bounding-box of a purely textual node: i.e., retrieving the width of the word foo inside the following HTML tag:

<span>abc foo xyz</span>

A workaround is to inject HTML tags around foo, but web-apps can monitor such changes and respond in ways that inhibit further manipulation. It can also report inaccurate metrics if it's targeted by a structural CSS selector:

/* In the above example, this would appear to insert a new line after `abc `: */
span > * {
    display: block;
}

</FMTEYEWTK>