From 8d36b8eb50795b501038860e555c4e1352920736 Mon Sep 17 00:00:00 2001 From: uwaa Date: Sat, 11 Jan 2025 05:48:11 +0000 Subject: [PATCH] reorganization --- rot.js | 67 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/rot.js b/rot.js index 7d5c7f2..79896f4 100644 --- a/rot.js +++ b/rot.js @@ -2,6 +2,7 @@ // one rotten apple spoils the bunch (() => { + //Helper functions function getPromiseFromEvent(item, event) { return new Promise((resolve) => { const listener = () => { @@ -32,7 +33,6 @@ }); } - function sex(sex) { return sex // Sex } @@ -41,13 +41,7 @@ return list ? list[list.length * Math.random() | 0] : null; } - // Rot music player - const audio = document.createElement("audio"); - audio.loop = true; - audio.id = "user-music"; - audio.style = "display:none;"; - localStorage.audiovolume = (audio.volume = localStorage.audiovolume ? localStorage.audiovolume / 100 : 0.5) * 100; - + //Music functions function setMusic(url) { if (audio.src == url || (!url && audio.src === window.location.toString())) return; @@ -77,7 +71,6 @@ } } - //Audio control events function volumeSet(number) { localStorage.audiovolume = Math.round((audio.volume = number) * 100); updateVolumeLabel(); @@ -89,26 +82,6 @@ document.getElementById("user-audio-percentage").innerHTML = Math.round(audio.volume * 100) + "%"; } - //Initialize audio controls - waitUntil("#music-controls").then((controls) => { - updateVolumeLabel(); - controls.querySelector("#music-up").onclick = () => volumeAdd(0.05); - controls.querySelector("#music-down").onclick = () => volumeAdd(-0.05); - }) - - waitUntil("#music-slider").then((slider) => { - updateVolumeLabel(); - slider.oninput = () => volumeSet(slider.value / 100); - }) - - waitUntil("#music-mute").then((box) => { - audio.muted = box.checked = localStorage.audiomuted === "true"; - box.addEventListener('click', () => { - localStorage.audiomuted = audio.muted = box.checked; - playMusic(); - }) - }); - //Theme application function applyMainTheme() { console.log("Applying main theme"); @@ -243,9 +216,34 @@ } } - //Monkey patches - addEventListener('locationchange', updateRot); - + //Rot music player + const audio = document.createElement("audio"); + audio.loop = true; + audio.id = "user-music"; + audio.style = "display:none;"; + localStorage.audiovolume = (audio.volume = localStorage.audiovolume ? localStorage.audiovolume / 100 : 0.5) * 100; + + //Initialize audio controls and event listeners + waitUntil("#music-controls").then((controls) => { + updateVolumeLabel(); + controls.querySelector("#music-up").onclick = () => volumeAdd(0.05); + controls.querySelector("#music-down").onclick = () => volumeAdd(-0.05); + }) + + waitUntil("#music-slider").then((slider) => { + updateVolumeLabel(); + slider.oninput = () => volumeSet(slider.value / 100); + }) + + waitUntil("#music-mute").then((box) => { + audio.muted = box.checked = localStorage.audiomuted === "true"; + box.addEventListener('click', () => { + localStorage.audiomuted = audio.muted = box.checked; + playMusic(); + }) + }); + + //Monkey patches and event listeners const oldPushState = history.pushState; history.pushState = function pushState() { const ret = oldPushState.apply(this, arguments); @@ -260,9 +258,8 @@ return ret; }; - window.addEventListener('popstate', () => { - updateRot(); - }); + addEventListener('locationchange', updateRot); + addEventListener('popstate', updateRot); })(); console.log("rot.js loaded"); \ No newline at end of file