reorganization

This commit is contained in:
uwaa 2025-01-11 05:48:11 +00:00
parent 9bbd44a557
commit 8d36b8eb50

65
rot.js
View file

@ -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");