m1l / Everything-Metric

Edge (Chromium) and Chrome Extension for converting USCS sites to Metric / SI
62 stars 15 forks source link

Does not convert 'F' unit #8

Open haarp opened 4 years ago

haarp commented 4 years ago

Hello and thanks for this extension!

Many Murkans fail to understand that their temperature unit is "degrees Fahrenheit" and just say things liek 100F instead of 100°F. This extension does notice or convert these. could that be fixed?

Thanks!

getsnoopy commented 4 years ago

100F, ignoring the lack of a space between the quantity and the unit symbol, means "100 Farads", a unit of electrical capacitance.

MaZZly commented 2 years ago

@getsnoopy could this be added as an option (pretty please), although it not being "scientifically correct".

Similar to https://github.com/m1l/Everything-Metric/issues/14 usually people on reddit, and some recipe sites, only write out 100F instead of the correct 100°F

getsnoopy commented 2 years ago

Well the correct formatting would be 100 °F (the space is required), but yes, as an extension, it should be as flexible/forgiving as possible in recognizing units. But that's for the maintainer to decide.

MaZZly commented 2 years ago

Yep, I think it would be best as an optional setting for those who are not as strict with their units :)

For now I just wrote my own lazy TamperMonkey script that does the same:

// ==UserScript==
// @name         F->C convert
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Crude conversion of **F into Celsius equivalent
// @author       You
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    const regex = /(\d+)F/gi;
    const fahrenheitToCelsius = fahrenheit => (fahrenheit - 32) * 5/9;

    var convertUnits = function () {
        let paragraphs = document.querySelectorAll("p");
        function farenheitReplace(match, p1, p2) {
            return p1 + 'F【'+ Math.round(fahrenheitToCelsius(p1)*10)/10 + 'C】';
        }
        for (let i = 0; i < paragraphs.length; i++) {
            paragraphs[i].innerHTML = paragraphs[i].innerHTML.replace(regex, farenheitReplace);
        }
    }
    convertUnits();
})();
mirh commented 1 year ago

https://github.com/askielboe/Everything-Metric/commit/e6979517faa959e7c903aff30f538544e2892745