Automatically converts imperial units to metric units
< Commentaires sur Universal metric translator
I fixed some bugs and implemented your suggested features + some more. I still haven't been able to get double quote (") work as inch unit. It worked before and then stopped. I might release the code with or without that working soon.
I was not aware of this discussion. My apologies for the inactivity @Qon can you post what code you have? I will take a look to see if I can work with it.
I have small graphical bug with my fanfiction script and this script so I had this script disabled mostly. So more testing would be beneficial.
Some of your bugs have been fixed. I added some comments in the code that you should read.
https://pastebin.com/7kHrjvzN
I am testing the script now. Look good! I will upload it soon. Please notify me if your graphical bug is related to this script.
Is 1 1/2 inch
== 1/2 inch
== 0.5 inch
?
Or is 1 1/2 inch
== 1.5 inch
?
1 1/2 inch == 1.5 inch
The space is '\s' on line 19. Solves example #2 in OP. It's somewhat common to express non-integers as a fraction expression this way instead of doing it with decimals when it's imperial units.
The graphical bug occurs only when both this script and my script are both enabled. Some borders with a specific style (so one every 6 chapters) are not visible. Some classes have numbers (which is unusual) in it so maybe something like:
<div class="border 5">
is mistaken as something with 5 inches of something and text replaced. Another thing that could be the cause: The style is added to the html document and other sites have all CSS is in a separate file which is not affected by any text replacements in the HTML at all. Not sure if UMT modifies text in style tags though, was a while since I went through the code now.
Also I really hope I managed to completely get rid of all infinite re-replacement bugs also. Those were annoying to get while I wrote it. Before I got it working it would replace 1 inch with 1 inch [2.54 cm] and then try to replace the 1 inch in the result again... It's easier to get it to work if the 1 inch part is modified in some way but that looked worse in the pages. That's what the regex code on line 22 prevents. It makes no followed by '[' or ']' to be replaced, by failing to match in those cases.
I didn't had much time to improve the script. I will continue to improve it at some point. For now I have created a github project so people can more easily contribute code: https://github.com/Benny-/universal-metric-translator
Some suggestions
Thank you for this script, it's very convenient. I have a few ideas, maybe you could implement them one day.
1. Metric values rounding. 6 digits after the decimal point is too much.
2. Compound fractions support (e.g. "1 3/4 oz").
3. Ability to view the original value on hover. Or maybe always display imperial units in brackets.