/*! * Sauna Session Planner — interface * (c) 2026 DIVELUX Inc. MIT License. https://diveluxsaunahat.com * * Mounts into every
on the page. * Optional attributes on that element: * data-ssp-sync-url keep the address bar in step with the inputs * data-ssp-share-url="..." base address for "copy link" (default: this page) * data-ssp-heading="h3" heading level for section titles (default h2) */ (function () { 'use strict'; var P = window.SaunaPlanner; if (!P) return; var SITE = 'https://diveluxsaunahat.com'; function esc(s) { return String(s).replace(/[&<>"]/g, function (c) { return { '&': '&', '<': '<', '>': '>', '"': '"' }[c]; }); } function fmtDur(min) { if (min < 60) return min + ' min'; var h = Math.floor(min / 60), m = min % 60; return h + ' h' + (m ? ' ' + m + ' min' : ''); } function fmtClock(min) { return Math.floor(min / 60) + ':' + String(min % 60).padStart(2, '0'); } function fmtTimer(ms) { var s = Math.max(0, Math.ceil(ms / 1000)); return String(Math.floor(s / 60)).padStart(2, '0') + ':' + String(s % 60).padStart(2, '0'); } function plural(n, word) { return n + ' ' + word + (n === 1 ? '' : 's'); } function glasses(n) { return n + (n === 1 ? ' glass' : ' glasses'); } function mount(root) { var H = /^h[2-4]$/.test(root.getAttribute('data-ssp-heading') || '') ? root.getAttribute('data-ssp-heading') : 'h2'; var state = P.normalize(P.fromQuery(location.search)); var current = null; // latest plan /* ---------- skeleton ---------- */ var typeRadios = Object.keys(P.TYPES).map(function (k) { return ''; }).join(''); var levelRadios = Object.keys(P.LEVELS).map(function (k) { return ''; }).join(''); root.innerHTML = '
' + '
' + '
Kind of sauna' + '
' + typeRadios + '
' + '

' + '
' + '
' + '
Unit' + '' + '' + '
' + '' + '' + '' + '

' + '
Your experience' + '
' + levelRadios + '
' + '

' + '
' + '' + '' + '' + '
' + '
' + '
' + '
' + '<' + H + ' class="ssp-kicker" id="ssp-plan-h">Your plan' + '

' + '

' + '

' + '' + '' + '
' + '
    ' + '
      ' + '

      Step out if you feel dizzy, sick, faint, or just wrong. A planning aid, not medical advice. ' + 'Sauna Session Planner by DIVELUX, diveluxsaunahat.com

      ' + '
      ' + '' + '' + '' + '' + '
      ' + '
      ' + '
      ' + '<' + H + ' class="ssp-kicker" id="ssp-timer-h">Round timer' + '

      ' + '

      ' + '

      ' + '

      ' + '
      ' + '' + '' + '' + '
      ' + '' + '

      Leave the phone outside the hot room, where you can hear it. Heat is hard on batteries.

      ' + '
      ' + '
      ' + '
      ' + '
      ' + '
      ' + '<' + H + ' class="ssp-h" id="ssp-ladder-h">The heat ladder' + '

      ' + '
        ' + '

        An illustration, not a measurement. It assumes the thermometer hangs at head height on the upper bench ' + 'and that the air cools in a straight line toward the floor. Real rooms differ with the heater, the vents and how recently the door opened.

        ' + '
        ' + '
        ' + '<' + H + ' class="ssp-h ssp-h--s">Why people wear a wool hat in there' + '

        ' + '

        Wool felt passes heat slowly, the same reason an oven mitt works. A thick felt hat, worn dry, keeps the hottest air in the room ' + 'off your hair and scalp, so your head warms up at the pace of the rest of you. It does not make a longer round a good idea. The plan above stays the plan.

        ' + '

        We make ours by hand from 100% wool felt, 4–5 mm thick. See the DIVELUX sauna hats

        ' + '
        ' + '
        ' + '
        ' + '
        ' + '<' + H + ' class="ssp-h" id="ssp-out-h">When to step out' + '

        The timer is a ceiling, not a target. Leave right away, sit somewhere cool and drink water if you notice any of these:

        ' + '' + '

        If it does not pass within a few minutes of cooling down, get medical help.

        ' + '
        ' + '
        ' + '<' + H + ' class="ssp-h" id="ssp-before-h">Before you go in' + '' + '

        Not medical advice. This planner gives general, conservative conventions for healthy adults. ' + 'It does not know your health. If you are pregnant, have a heart or blood pressure condition, take medication, or are unsure, talk to your doctor before using a sauna.

        ' + '
        ' + '
        ' + '<' + H + ' class="ssp-h" id="ssp-conv-h">°F to °C converter' + '
        ' + '' + '' + '' + '
        ' + '

        Type in either box. Water boils at 212 °F, which is 100 °C.

        ' + '
        ' + '
        '; var $ = function (name) { return root.querySelector('[data-o="' + name + '"]'); }; var tempInput = root.querySelector('#ssp-temp'); var totalInput = root.querySelector('#ssp-total'); function radios(name) { return [].slice.call(root.querySelectorAll('input[name="' + name + '"]')); } function check(name, value) { radios(name).forEach(function (r) { r.checked = r.value === value; }); } /* ---------- render ---------- */ var liveTimer = null; function benchText(b) { return b === 'lower' ? 'Sit on the lower bench.' : b === 'upper' ? 'Upper bench if it feels easy, lower if not.' : 'Sit on whichever bench feels right.'; } function render() { var t = P.TYPES[state.type], range = t[state.unit]; check('ssp-type', state.type); check('ssp-level', state.level); check('ssp-unit', state.unit); tempInput.min = range.min; tempInput.max = range.max; tempInput.step = state.unit === 'f' ? 5 : 1; tempInput.value = state.temp; totalInput.value = state.total; var other = state.unit === 'f' ? Math.round(P.f2c(state.temp)) + '\u00a0°C' : Math.round(P.c2f(state.temp)) + '\u00a0°F'; $('temp').innerHTML = esc(state.temp) + '°' + state.unit.toUpperCase() + 'about ' + other + ''; tempInput.setAttribute('aria-valuetext', state.temp + ' degrees ' + (state.unit === 'f' ? 'Fahrenheit' : 'Celsius')); $('tmin').textContent = range.min + '°'; $('tmax').textContent = range.max + '°'; $('thint').textContent = 'Usual range for this kind of sauna: ' + range.min + '–' + range.max + '\u00a0°' + state.unit.toUpperCase() + '.'; root.querySelector('#ssp-type-hint').textContent = t.hint; $('lhint').textContent = P.LEVELS[state.level].hint + '.'; $('total').textContent = fmtDur(state.total); totalInput.setAttribute('aria-valuetext', fmtDur(state.total)); var p = current = P.plan(state); var w = p.water; $('headline').textContent = p.rounds === 1 ? 'One round of ' + p.roundMin + ' minutes' : p.rounds + ' rounds of ' + p.roundMin + ' minutes'; var sub = (p.rounds > 1 ? 'Cool down for ' + p.restMin + ' minutes between rounds and ' + p.coolMin + ' at the end. ' : 'Then cool down for at least ' + p.coolMin + ' minutes. ') + fmtDur(p.usedMin) + ' in all'; sub += p.spareMin > 0 ? ', with ' + fmtDur(p.spareMin) + ' to spare for a longer cool-down or a shower.' : '.'; $('sub').textContent = sub; // timeline $('tl').setAttribute('aria-label', 'Session timeline: ' + p.segments.map(function (s) { return s.label + ' ' + s.min + ' minutes'; }).join(', ') + '.'); $('tl').innerHTML = p.segments.map(function (s) { return '' + s.min + ''; }).join('') + ''; $('tlend').textContent = fmtDur(p.usedMin) + ' total'; $('stats').innerHTML = stat('In the heat', fmtDur(p.heatMin), plural(p.rounds, 'round')) + stat('Each break', p.rounds > 1 ? p.restMin + ' min' : p.coolMin + ' min', p.rounds > 1 ? 'at least as long as the round' : 'after the round') + stat('Water', glasses(w.glasses), w.oz + ' fl oz, about ' + w.liters + ' L') + (p.bench ? stat('Where to sit', p.bench === 'either' ? 'Your call' : p.bench.charAt(0).toUpperCase() + p.bench.slice(1) + ' bench', p.bench === 'lower' ? 'cooler air, easier start' : p.bench === 'upper' ? 'hottest seat; move down any time' : 'lower is always fine') : stat('Where to sit', 'Facing the panels', 'no bench levels to pick')); var steps = '
      1. BeforeGet ready' + 'Quick shower, towel off, one glass of water.
      2. '; p.segments.forEach(function (s) { var body; if (s.kind === 'heat') body = 'Round ' + s.index + ', ' + s.min + ' min' + (p.bench ? benchText(p.bench) : 'Sit back and let the panels do the work.') + ' Leave sooner if you want to.'; else if (s.kind === 'rest') body = 'Cool down, ' + s.min + ' minFresh air or a cool shower, then sit. One glass of water.'; else body = 'Final cool-down, ' + s.min + ' min or moreRinse off, sit until your pulse feels normal, and drink ' + glasses(w.after) + ' of water over the next hour.'; steps += '
      3. ' + fmtClock(s.start) + '' + body + '
      4. '; }); $('steps').innerHTML = steps; $('notes').innerHTML = p.notes.map(function (n) { return '
      5. ' + esc(n) + '
      6. '; }).join(''); // ladder var lad = P.ladder(state); var top = lad[0].c, floor = lad[lad.length - 1].c; $('ladder').innerHTML = lad.map(function (r, i) { var width = top === floor ? 100 : 22 + 78 * (r.c - floor) / (top - floor); return '
      7. ' + '' + esc(r.label) + (r.thermometer ? 'thermometer' : '') + '' + '' + (state.unit === 'f' ? r.f : r.c) + '°' + '
      8. '; }).join(''); var head = lad[1], feet = lad[3]; var diff = state.unit === 'f' ? head.f - feet.f : head.c - feet.c; $('ladlead').textContent = 'Hot air rises, so one room holds several climates. With ' + (state.unit === 'f' ? head.f + '\u00a0°F' : head.c + '\u00a0°C') + ' on the thermometer, a simple estimate puts the air at the ceiling near ' + (state.unit === 'f' ? lad[0].f + '\u00a0°F' : lad[0].c + '\u00a0°C') + ' and the air at the floor near ' + (state.unit === 'f' ? lad[4].f + '\u00a0°F' : lad[4].c + '\u00a0°C') + '.'; $('hattext').textContent = state.type === 'infrared' ? 'An infrared cabin heats you with panels more than with air, so the layers are shallow. In a Finnish sauna or a banya the gap is far wider, and your head is always the highest part of you.' : 'Sit on the upper bench and the air around your head is roughly ' + diff + '\u00a0°' + state.unit.toUpperCase() + ' warmer than the air at your feet. Your head is always in the hottest layer you occupy.'; // screen readers: one calm announcement after the sliders settle clearTimeout(liveTimer); liveTimer = setTimeout(function () { $('live').textContent = $('headline').textContent + '. ' + sub + ' Water: ' + w.glasses + ' glasses.'; }, 700); timerReset(timer.started ? 'Plan changed. Timer reset.' : ''); syncUrl(); } function stat(k, v, note) { return '
        ' + esc(k) + '
        ' + esc(v) + '' + esc(note) + '
        '; } /* ---------- inputs ---------- */ root.querySelector('.ssp-form').addEventListener('submit', function (e) { e.preventDefault(); }); root.addEventListener('change', function (e) { var el = e.target; if (el.name === 'ssp-type') { state.type = el.value; state.temp = P.TYPES[state.type][state.unit].def; render(); } else if (el.name === 'ssp-level') { state.level = el.value; render(); } else if (el.name === 'ssp-unit') { state.temp = P.convertTemp(state.type, state.temp, el.value); state.unit = el.value; render(); } }); tempInput.addEventListener('input', function () { state.temp = +tempInput.value; render(); }); totalInput.addEventListener('input', function () { state.total = +totalInput.value; render(); }); var urlTimer = null; function syncUrl() { if (!root.hasAttribute('data-ssp-sync-url') || !window.history || !history.replaceState) return; clearTimeout(urlTimer); urlTimer = setTimeout(function () { try { history.replaceState(null, '', location.pathname + '?' + P.toQuery(state)); } catch (e) { /* file:// etc. */ } }, 400); } function shareUrl() { var base = root.getAttribute('data-ssp-share-url') || (location.origin + location.pathname); return base + (base.indexOf('?') < 0 ? '?' : '&') + P.toQuery(state); } /* ---------- converter ---------- */ var cf = $('cf'), cc = $('cc'); function r1(n) { return Math.round(n * 10) / 10; } cf.addEventListener('input', function () { cc.value = cf.value === '' || isNaN(+cf.value) ? '' : r1(P.f2c(+cf.value)); }); cc.addEventListener('input', function () { cf.value = cc.value === '' || isNaN(+cc.value) ? '' : r1(P.c2f(+cc.value)); }); cc.value = r1(P.f2c(+cf.value)); /* ---------- timer ---------- */ var timer = { idx: 0, left: 0, endAt: 0, running: false, started: false, done: false, tick: null }; var audio = null, wake = null; var startBtn = root.querySelector('[data-a="start"]'); function seg() { return current.segments[timer.idx]; } function segName(s) { return s.kind === 'heat' ? 'Round ' + s.index + ' of ' + current.rounds + ': in the heat' : s.kind === 'rest' ? 'Cool-down ' + s.index + ' of ' + (current.rounds - 1) : 'Final cool-down'; } function timerPaint() { var s = seg(), next = current.segments[timer.idx + 1]; var left = timer.running ? Math.max(0, timer.endAt - Date.now()) : timer.left; $('clock').textContent = timer.done ? '00:00' : fmtTimer(left); $('tphase').textContent = timer.done ? 'Session done' : segName(s); $('tnext').textContent = timer.done ? 'Keep cooling down and drink your water.' : next ? 'Next: ' + (next.kind === 'heat' ? 'round ' + next.index : next.kind === 'rest' ? 'cool-down' : 'final cool-down') + ', ' + next.min + ' min' : 'Last part of the session'; startBtn.textContent = timer.running ? 'Pause' : timer.done ? 'Start again' : timer.started ? 'Resume' : 'Start'; root.querySelector('.ssp-timer').setAttribute('data-phase', timer.done ? 'done' : s.kind); var mark = $('mark'); if (mark) { if (timer.started || timer.done) { var elapsed = timer.done ? current.usedMin : s.start + s.min - left / 60000; mark.hidden = false; mark.style.left = Math.min(100, 100 * elapsed / current.usedMin).toFixed(2) + '%'; } else mark.hidden = true; } } function timerReset(msg) { clearInterval(timer.tick); timer.idx = 0; timer.running = false; timer.started = false; timer.done = false; timer.left = current.segments[0].min * 60000; releaseWake(); $('tlive').textContent = msg || ''; timerPaint(); } function timerStart() { if (timer.done) timerReset(''); timer.running = true; timer.started = true; timer.endAt = Date.now() + timer.left; clearInterval(timer.tick); timer.tick = setInterval(timerTick, 250); requestWake(); $('tlive').textContent = segName(seg()) + ' started, ' + Math.ceil(timer.left / 60000) + ' minutes.'; timerPaint(); } function timerPause() { timer.left = Math.max(0, timer.endAt - Date.now()); timer.running = false; clearInterval(timer.tick); releaseWake(); $('tlive').textContent = 'Timer paused.'; timerPaint(); } // Uses wall-clock time, so a tab that was asleep catches up when it wakes. function timerAdvance(fromSkip) { var ended = seg(); if (timer.idx >= current.segments.length - 1) { clearInterval(timer.tick); timer.running = false; timer.done = true; timer.left = 0; releaseWake(); if (!fromSkip) beep('done'); $('tlive').textContent = 'Session done. Keep cooling down and drink your water.'; return false; } timer.idx++; var s = seg(); if (fromSkip) { timer.left = s.min * 60000; timer.endAt = Date.now() + timer.left; } else { timer.endAt += s.min * 60000; } if (!fromSkip) beep(ended.kind === 'heat' ? 'out' : 'in'); $('tlive').textContent = (ended.kind === 'heat' ? 'Time to step out. ' : 'Break over. ') + segName(s) + ', ' + s.min + ' minutes.'; return true; } function timerTick() { var guard = 0; while (timer.running && Date.now() >= timer.endAt && guard++ < 20) { if (!timerAdvance(false)) break; } timerPaint(); } function timerSkip() { if (timer.done) return; var wasRunning = timer.running; timerAdvance(true); if (!timer.done && !wasRunning) { timer.started = true; } timerPaint(); } function beep(kind) { if (navigator.vibrate) { try { navigator.vibrate(kind === 'done' ? [300, 150, 300, 150, 600] : [300, 150, 300]); } catch (e) { /* ignore */ } } if (!$('sound').checked || !audio) return; var notes = kind === 'out' ? [880, 880, 880] : kind === 'in' ? [587, 784] : [784, 659, 523]; var t0 = audio.currentTime + 0.05; notes.forEach(function (hz, i) { var osc = audio.createOscillator(), gain = audio.createGain(); var at = t0 + i * 0.42, len = kind === 'done' && i === 2 ? 0.9 : 0.3; osc.type = 'sine'; osc.frequency.value = hz; gain.gain.setValueAtTime(0.0001, at); gain.gain.exponentialRampToValueAtTime(0.5, at + 0.02); gain.gain.exponentialRampToValueAtTime(0.0001, at + len); osc.connect(gain); gain.connect(audio.destination); osc.start(at); osc.stop(at + len + 0.05); }); } function initAudio() { // Must happen inside a tap or click, or mobile browsers keep it muted. try { var AC = window.AudioContext || window.webkitAudioContext; if (!audio && AC) audio = new AC(); if (audio && audio.state === 'suspended') audio.resume(); } catch (e) { audio = null; } } function requestWake() { if (!('wakeLock' in navigator) || wake) return; navigator.wakeLock.request('screen').then(function (lock) { if (!timer.running) { lock.release(); return; } wake = lock; lock.addEventListener('release', function () { if (wake === lock) wake = null; }); }).catch(function () { /* low battery, not allowed, etc. */ }); } function releaseWake() { if (wake) { var w = wake; wake = null; try { w.release(); } catch (e) { /* ignore */ } } } document.addEventListener('visibilitychange', function () { if (document.visibilityState === 'visible' && timer.running) { requestWake(); timerTick(); } }); /* ---------- buttons ---------- */ root.addEventListener('click', function (e) { var btn = e.target.closest ? e.target.closest('[data-a]') : null; if (!btn || !root.contains(btn)) return; var a = btn.getAttribute('data-a'); if (a === 'start') { initAudio(); if (timer.running) timerPause(); else timerStart(); } else if (a === 'skip') { initAudio(); timerSkip(); } else if (a === 'reset') { timerReset('Timer reset.'); } else if (a === 'print') { document.documentElement.classList.add('ssp-printing'); var done = function () { document.documentElement.classList.remove('ssp-printing'); window.removeEventListener('afterprint', done); }; window.addEventListener('afterprint', done); window.print(); } else if (a === 'share') { var url = shareUrl(), box = root.querySelector('.ssp-sharebox'), field = $('shareurl'); field.value = url; box.hidden = false; var ok = function () { $('sharestatus').textContent = 'Link copied.'; }; var manual = function () { field.focus(); field.select(); $('sharestatus').textContent = 'Copy the link below.'; }; if (navigator.clipboard && navigator.clipboard.writeText) navigator.clipboard.writeText(url).then(ok, manual); else manual(); } }); render(); } function init() { [].forEach.call(document.querySelectorAll('[data-ssp]'), function (el) { if (el.getAttribute('data-ssp-ready')) return; el.setAttribute('data-ssp-ready', '1'); mount(el); }); } if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init); else init(); })();