diff --git a/kifu/kifu-pwa/converter.css b/kifu/kifu-pwa/converter.css new file mode 100644 index 0000000..401fef8 --- /dev/null +++ b/kifu/kifu-pwa/converter.css @@ -0,0 +1,38 @@ +html { + background: rgb(243, 243, 243); + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + font-size: 15pt; +} + +html, body { + height: 100%; + margin: 0; +} + +body { + display: grid; + place-items: center; +} + +#converter { + width: 15rem; + padding: 2rem; + border-radius: .5rem; + box-shadow: 0 0 2rem 0 #0001; + display: flex; + flex-direction: column; + align-items: center; +} + +#converter input, #converter select { + font-family: inherit; + font-size: inherit; + margin-block-end: 1rem; + text-align: center; + width: 10rem; +} + +#converter #output-temp { + font-size: 2rem; + font-weight: bold; +} diff --git a/kifu/kifu-pwa/converter.js b/kifu/kifu-pwa/converter.js new file mode 100644 index 0000000..a28fa83 --- /dev/null +++ b/kifu/kifu-pwa/converter.js @@ -0,0 +1,42 @@ +const inputField = document.getElementById('input-temp'); +const fromUnitField = document.getElementById('input-unit'); +const toUnitField = document.getElementById('output-unit'); +const outputField = document.getElementById('output-temp'); +const form = document.getElementById('converter'); + +function convertTemp(value, fromUnit, toUnit) { + if (fromUnit === 'c') { + if (toUnit === 'f') { + return value * 9 / 5 + 32; + } else if (toUnit === 'k') { + return value + 273.15; + } + return value + } + if (fromUnit === 'f') { + if (toUnit === 'c') { + return (value - 32) * 5 / 9; + } else if (toUnit === 'k') { + return (value + 459.67) * 5 / 9; + } + return value; + } + if (fromUnit === 'k') { + if (toUnit === 'c') { + return value - 273.15; + } else if (toUnit === 'f') { + return value * 9 / 5 - 459.67; + } + return value; + } + throw new Error('Invalid unit'); +} + +form.addEventListener('input', () => { + const inputTemp = parseFloat(inputField.value); + const fromUnit = fromUnitField.value; + const toUnit = toUnitField.value; + + const outputTemp = convertTemp(inputTemp, fromUnit, toUnit); + outputField.value = (Math.round(outputTemp * 100) / 100) + ' ' + toUnit.toUpperCase(); +}); diff --git a/kifu/kifu-pwa/icon512.png b/kifu/kifu-pwa/icon512.png new file mode 100644 index 0000000..3f46c9d Binary files /dev/null and b/kifu/kifu-pwa/icon512.png differ diff --git a/kifu/kifu-pwa/index.html b/kifu/kifu-pwa/index.html new file mode 100644 index 0000000..57389ec --- /dev/null +++ b/kifu/kifu-pwa/index.html @@ -0,0 +1,36 @@ + + +
+ + + +