Convert units to Celcius

attempts to convert all Farenheit temperature measurments to Celcius. Not infallable, but decent for cooking measurements

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name       Convert units to Celcius
// @namespace  https://github.com/daniel-simpson
// @version    0.2
// @description  attempts to convert all Farenheit temperature measurments to Celcius.  Not infallable, but decent for cooking measurements
// @match      http://*/*
// @copyright  2015+, Daniel Simpson, Melbourne, Australia
// ==/UserScript==

var config = {
  pattern: />[^<>]*\s((\d{1,3}(\.\d*)?)[°°\s]{0,2} ?F)\s[^<>]*<\//g,
  debug: 1,
  rerun: 5,
  dp: 3,
    showTooltip: true
};

var generateReplacementString = function(tempF) {
  var tempC = (((tempF - 32) * 5) / 9).toFixed(config.dp);
  if(config.showTooltip) {
    return "<span title='"+tempF+"°F'>" + tempC + "°C</span>";
  }
  return "" + tempC + "°C";
};

var runConversion = function() {
  if(config.debug) console.log("Starting temperature fix, replacing farenheit with celcius...");
  var match = config.pattern.exec(document.body.innerHTML);  
  
  while(match) {   
    //var itemTextF = match[0];        //Full text node            >assudygsudfkujhsdbfjhabsd sadhgfujsh 123F ajshbda</
    var replaceTextF = match[1];     //Match including unit      123F
    var tempF = match[2];            //Temperature value         123
          
    var replaceTextC = generateReplacementString(tempF);
    
    if(config.debug) console.log("Replacing " + replaceTextF + " with " + replaceTextC);
    document.body.innerHTML = document.body.innerHTML.replace(new RegExp(replaceTextF, 'g'), replaceTextC);
      
    match = config.pattern.exec(document.body.innerHTML);
  }
  if(config.debug) console.log('Completed conversion without errors');
};

for(var i=0;i<config.rerun;i=i+1) {
  setTimeout(runConversion,  500);
}