Fix volume slider, add 0-255 number input
This commit is contained in:
parent
3761b13649
commit
35d979a06a
3 changed files with 40 additions and 8 deletions
|
|
@ -984,3 +984,17 @@ body.dnd-mode .timer-display {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.volume-num {
|
||||||
|
width: 44px;
|
||||||
|
background: var(--surface, #1e1e2e);
|
||||||
|
border: 1px solid var(--border, #333);
|
||||||
|
border-radius: 4px;
|
||||||
|
color: var(--fg, #fff);
|
||||||
|
font-size: 0.8rem;
|
||||||
|
padding: 2px 4px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.volume-num::-webkit-inner-spin-button,
|
||||||
|
.volume-num::-webkit-outer-spin-button { opacity: 0.4; }
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ function playStation(url, name, stationId) {
|
||||||
|
|
||||||
audio.src = url;
|
audio.src = url;
|
||||||
const volSlider = document.getElementById('volume');
|
const volSlider = document.getElementById('volume');
|
||||||
if (volSlider) audio.volume = volSlider.value / 100;
|
if (volSlider) audio.volume = volSlider.value / 255;
|
||||||
audio.play().catch(() => {
|
audio.play().catch(() => {
|
||||||
// Browser may block autoplay; the user needs to interact first
|
// Browser may block autoplay; the user needs to interact first
|
||||||
console.warn('Audio play blocked by browser policy.');
|
console.warn('Audio play blocked by browser policy.');
|
||||||
|
|
@ -181,10 +181,28 @@ function escapeAttr(s) {
|
||||||
// Volume
|
// Volume
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
document.getElementById('volume').addEventListener('input', function () {
|
function setVolume(val) {
|
||||||
audio.volume = this.value / 100;
|
val = Math.max(0, Math.min(255, Math.round(val)));
|
||||||
localStorage.setItem('diora_volume', this.value);
|
audio.volume = val / 255;
|
||||||
});
|
localStorage.setItem('diora_volume', val);
|
||||||
|
const slider = $('volume');
|
||||||
|
const numInput = $('volume-num');
|
||||||
|
if (slider) slider.value = val;
|
||||||
|
if (numInput) numInput.value = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
const volSliderEl = document.getElementById('volume');
|
||||||
|
if (volSliderEl) {
|
||||||
|
['input', 'change', 'mousemove', 'touchmove'].forEach(evt =>
|
||||||
|
volSliderEl.addEventListener(evt, function () { setVolume(this.value); })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const volNumEl = document.getElementById('volume-num');
|
||||||
|
if (volNumEl) {
|
||||||
|
volNumEl.addEventListener('change', function () { setVolume(this.value); });
|
||||||
|
volNumEl.addEventListener('input', function () { setVolume(this.value); });
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// SSE metadata
|
// SSE metadata
|
||||||
|
|
@ -1045,8 +1063,7 @@ function toggleContrast() {
|
||||||
if (volSlider) {
|
if (volSlider) {
|
||||||
const saved = localStorage.getItem('diora_volume');
|
const saved = localStorage.getItem('diora_volume');
|
||||||
const vol = saved !== null ? parseInt(saved, 10) : parseInt(volSlider.value, 10);
|
const vol = saved !== null ? parseInt(saved, 10) : parseInt(volSlider.value, 10);
|
||||||
volSlider.value = vol;
|
setVolume(vol);
|
||||||
audio.volume = vol / 100;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load recommendations on page load
|
// Load recommendations on page load
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@
|
||||||
<button class="btn btn-play" id="play-stop-btn" onclick="togglePlayStop()" style="display:none;">▶ Play</button>
|
<button class="btn btn-play" id="play-stop-btn" onclick="togglePlayStop()" style="display:none;">▶ Play</button>
|
||||||
<label class="volume-label">
|
<label class="volume-label">
|
||||||
<span>vol</span>
|
<span>vol</span>
|
||||||
<input type="range" id="volume" min="0" max="100" value="80" class="volume-slider">
|
<input type="range" id="volume" min="0" max="255" value="204" class="volume-slider">
|
||||||
|
<input type="number" id="volume-num" min="0" max="255" value="204" class="volume-num">
|
||||||
</label>
|
</label>
|
||||||
<button class="btn btn-save" id="save-station-btn" style="display:none;" onclick="saveCurrentStation()">★ Save</button>
|
<button class="btn btn-save" id="save-station-btn" style="display:none;" onclick="saveCurrentStation()">★ Save</button>
|
||||||
<button class="btn-icon" id="dnd-btn" onclick="toggleDND()" title="Focus mode (hides UI, press Esc to exit)">⊙</button>
|
<button class="btn-icon" id="dnd-btn" onclick="toggleDND()" title="Focus mode (hides UI, press Esc to exit)">⊙</button>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue