From 3c793581b7d5b658dedaaaa9eb55f7d54c4d89a2 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 26 May 2020 17:59:21 +0200 Subject: [PATCH] Add per-browser temp unit selection Signed-off-by: DL6ER --- scripts/pi-hole/js/footer.js | 41 +++++++++++++++++++++++++++++++++- scripts/pi-hole/php/header.php | 31 +------------------------ settings.php | 29 ++++++++++++------------ 3 files changed, 55 insertions(+), 46 deletions(-) diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index f3773ca2..331cb92a 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -164,7 +164,6 @@ function initTheme() { // The theme selector is only available on the settings page var theme_selector = $('#theme-selector'); - console.log(theme_selector); if (theme_selector !== null) { theme_selector.change(function(){ themename = $(this).val(); @@ -174,6 +173,45 @@ function initTheme() { } } +function initCPUtemp() { + function setCPUtemp(unit) { + var temperature = parseFloat($("#rawtemp").text()); + var displaytemp = $("#tempdisplay"); + if (temperature !== NaN) { + switch (unit) { + case "K": + temperature = temperature + 273.15; + displaytemp.html(temperature.toFixed(1) + " °K"); + break; + + case "F": + temperature = (temperature * 9/5) + 32; + displaytemp.html(temperature.toFixed(1) + " °F"); + break; + + default: + displaytemp.html(temperature.toFixed(1) + " °C"); + break; + } + } + } + var tempunit = localStorage.getItem("tempunit"); + if (tempunit === null) { + tempunit = "C"; + } + setCPUtemp(tempunit); + + // The theme selector is only available on the settings page + var tempunit_selector = $('#tempunit-selector'); + if (tempunit_selector !== null) { + tempunit_selector.change(function(){ + tempunit = $(this).val(); + localStorage.setItem("tempunit", tempunit); + setCPUtemp(tempunit); + }); + } +} + $(function () { var enaT = $("#enableTimer"); var target = new Date(parseInt(enaT.html())); @@ -190,6 +228,7 @@ $(function () { applyCheckboxRadioStyle(); applyBoxedLayout(); initTheme(); + initCPUtemp(); // Run check immediately after page loading ... checkMessages(); diff --git a/scripts/pi-hole/php/header.php b/scripts/pi-hole/php/header.php index 9f60c3a9..9c387040 100644 --- a/scripts/pi-hole/php/header.php +++ b/scripts/pi-hole/php/header.php @@ -49,22 +49,6 @@ $celsius *= 1e-3; } - $kelvin = $celsius + 273.15; - $fahrenheit = ($celsius*9./5)+32.0; - - if(isset($setupVars['TEMPERATUREUNIT'])) - { - $temperatureunit = $setupVars['TEMPERATUREUNIT']; - } - else - { - $temperatureunit = "C"; - } - // Override temperature unit setting if it is changed via Settings page - if(isset($_POST["tempunit"])) - { - $temperatureunit = $_POST["tempunit"]; - } // Get user-defined temperature limit if set if(isset($setupVars['TEMPERATURE_LIMIT'])) { @@ -326,20 +310,7 @@ if($auth) { { echo "text-vivid-blue"; } - echo "\"> Temp: "; - if($temperatureunit === "F") - { - echo round($fahrenheit,1) . " °F"; - } - elseif($temperatureunit === "K") - { - echo round($kelvin,1) . " K"; - } - else - { - echo round($celsius,1) . " °C"; - } - echo ""; + ?>"\"> Temp: 
-

CPU Temperature Unit

-
- checked> - -
-
- checked> - -
-
- checked> - -

Administrator Email Address

@@ -1152,7 +1139,7 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array("sysadmin", "adlists", "

Checkbox and radio buttons

-
+
+
+
+

CPU Temperature Unit

+
+
+ +
+