reorganization
This commit is contained in:
parent
9bbd44a557
commit
8d36b8eb50
1 changed files with 32 additions and 35 deletions
67
rot.js
67
rot.js
|
@ -2,6 +2,7 @@
|
||||||
// one rotten apple spoils the bunch
|
// one rotten apple spoils the bunch
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
|
//Helper functions
|
||||||
function getPromiseFromEvent(item, event) {
|
function getPromiseFromEvent(item, event) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const listener = () => {
|
const listener = () => {
|
||||||
|
@ -32,7 +33,6 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function sex(sex) {
|
function sex(sex) {
|
||||||
return sex // Sex
|
return sex // Sex
|
||||||
}
|
}
|
||||||
|
@ -41,13 +41,7 @@
|
||||||
return list ? list[list.length * Math.random() | 0] : null;
|
return list ? list[list.length * Math.random() | 0] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rot music player
|
//Music functions
|
||||||
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;
|
|
||||||
|
|
||||||
function setMusic(url) {
|
function setMusic(url) {
|
||||||
if (audio.src == url || (!url && audio.src === window.location.toString()))
|
if (audio.src == url || (!url && audio.src === window.location.toString()))
|
||||||
return;
|
return;
|
||||||
|
@ -77,7 +71,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Audio control events
|
|
||||||
function volumeSet(number) {
|
function volumeSet(number) {
|
||||||
localStorage.audiovolume = Math.round((audio.volume = number) * 100);
|
localStorage.audiovolume = Math.round((audio.volume = number) * 100);
|
||||||
updateVolumeLabel();
|
updateVolumeLabel();
|
||||||
|
@ -89,26 +82,6 @@
|
||||||
document.getElementById("user-audio-percentage").innerHTML = Math.round(audio.volume * 100) + "%";
|
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
|
//Theme application
|
||||||
function applyMainTheme() {
|
function applyMainTheme() {
|
||||||
console.log("Applying main theme");
|
console.log("Applying main theme");
|
||||||
|
@ -243,9 +216,34 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Monkey patches
|
//Rot music player
|
||||||
addEventListener('locationchange', updateRot);
|
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;
|
const oldPushState = history.pushState;
|
||||||
history.pushState = function pushState() {
|
history.pushState = function pushState() {
|
||||||
const ret = oldPushState.apply(this, arguments);
|
const ret = oldPushState.apply(this, arguments);
|
||||||
|
@ -260,9 +258,8 @@
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener('popstate', () => {
|
addEventListener('locationchange', updateRot);
|
||||||
updateRot();
|
addEventListener('popstate', updateRot);
|
||||||
});
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
console.log("rot.js loaded");
|
console.log("rot.js loaded");
|
Loading…
Reference in a new issue