Move notification sound to admin
This commit is contained in:
+37
-1
@@ -9,6 +9,8 @@ const state = {
|
||||
events: null,
|
||||
statusFilter: "active",
|
||||
hideBots: localStorage.getItem("mf_admin_hide_bots") !== "0",
|
||||
soundMuted: localStorage.getItem("mf_admin_sound_muted") === "1",
|
||||
soundVolume: Number(localStorage.getItem("mf_admin_sound_volume") || 70),
|
||||
replyFiles: [],
|
||||
attentionTimer: null,
|
||||
attentionOn: false,
|
||||
@@ -19,6 +21,7 @@ const state = {
|
||||
const $ = (selector) => document.querySelector(selector);
|
||||
|
||||
boot();
|
||||
renderAdminSoundControls();
|
||||
|
||||
async function boot() {
|
||||
const me = await api("/api/admin/me").catch(() => null);
|
||||
@@ -47,6 +50,20 @@ $("#logoutButton").addEventListener("click", async () => {
|
||||
|
||||
$("#settingsButton").addEventListener("click", () => $("#settingsPanel").classList.remove("hidden"));
|
||||
$("#closeSettingsButton").addEventListener("click", () => $("#settingsPanel").classList.add("hidden"));
|
||||
$("#adminSoundToggle").addEventListener("click", () => {
|
||||
state.soundMuted = !state.soundMuted;
|
||||
if (!state.soundMuted && state.soundVolume <= 0) state.soundVolume = 70;
|
||||
localStorage.setItem("mf_admin_sound_muted", state.soundMuted ? "1" : "0");
|
||||
localStorage.setItem("mf_admin_sound_volume", String(state.soundVolume));
|
||||
renderAdminSoundControls();
|
||||
});
|
||||
$("#adminSoundVolume").addEventListener("input", (event) => {
|
||||
state.soundVolume = clamp(Number(event.target.value), 0, 100);
|
||||
state.soundMuted = state.soundVolume <= 0;
|
||||
localStorage.setItem("mf_admin_sound_volume", String(state.soundVolume));
|
||||
localStorage.setItem("mf_admin_sound_muted", state.soundMuted ? "1" : "0");
|
||||
renderAdminSoundControls();
|
||||
});
|
||||
$("#settingsForm").brand.addEventListener("input", (event) => {
|
||||
$("#settingsForm").brandHex.value = normalizeHexColor(event.target.value) || event.target.value;
|
||||
});
|
||||
@@ -775,12 +792,26 @@ function notify() {
|
||||
playNotifySound();
|
||||
}
|
||||
|
||||
function renderAdminSoundControls() {
|
||||
const toggle = $("#adminSoundToggle");
|
||||
const volume = $("#adminSoundVolume");
|
||||
if (!toggle || !volume) return;
|
||||
const safeVolume = clamp(state.soundVolume, 0, 100);
|
||||
toggle.classList.toggle("muted", state.soundMuted || safeVolume <= 0);
|
||||
toggle.setAttribute("aria-label", state.soundMuted ? "Zapnout zvuk notifikaci" : "Vypnout zvuk notifikaci");
|
||||
toggle.title = state.soundMuted ? "Zapnout zvuk notifikaci" : "Vypnout zvuk notifikaci";
|
||||
volume.value = String(safeVolume);
|
||||
volume.title = `Hlasitost ${safeVolume}%`;
|
||||
}
|
||||
|
||||
function playNotifySound() {
|
||||
const volume = clamp(state.soundVolume, 0, 100);
|
||||
if (state.soundMuted || volume <= 0) return;
|
||||
const AudioCtor = window.AudioContext || window.webkitAudioContext;
|
||||
if (!AudioCtor) return;
|
||||
const audio = new AudioCtor();
|
||||
const gain = audio.createGain();
|
||||
gain.gain.value = 0.055;
|
||||
gain.gain.value = 0.12 * (volume / 100);
|
||||
gain.connect(audio.destination);
|
||||
[0, 0.14].forEach((offset, index) => {
|
||||
const osc = audio.createOscillator();
|
||||
@@ -793,6 +824,11 @@ function playNotifySound() {
|
||||
setTimeout(() => audio.close().catch(() => {}), 520);
|
||||
}
|
||||
|
||||
function clamp(value, min, max) {
|
||||
if (!Number.isFinite(value)) return min;
|
||||
return Math.min(max, Math.max(min, value));
|
||||
}
|
||||
|
||||
function startAttention() {
|
||||
if (state.attentionTimer) return;
|
||||
const favicon = document.querySelector("link[rel='icon']");
|
||||
|
||||
Reference in New Issue
Block a user