initial commit
This commit is contained in:
commit
01cfdb1540
1 changed files with 180 additions and 0 deletions
180
rot.js
Normal file
180
rot.js
Normal file
|
@ -0,0 +1,180 @@
|
|||
// Rot.js
|
||||
// one rotten apple spoils the bunch
|
||||
|
||||
(() => {
|
||||
let oldPushState = history.pushState;
|
||||
history.pushState = function pushState() {
|
||||
let ret = oldPushState.apply(this, arguments);
|
||||
window.dispatchEvent(new Event('pushstate'));
|
||||
window.dispatchEvent(new Event('locationchange'));
|
||||
return ret;
|
||||
};
|
||||
|
||||
let oldReplaceState = history.replaceState;
|
||||
history.replaceState = function replaceState() {
|
||||
let ret = oldReplaceState.apply(this, arguments);
|
||||
window.dispatchEvent(new Event('replacestate'));
|
||||
window.dispatchEvent(new Event('locationchange'));
|
||||
return ret;
|
||||
};
|
||||
|
||||
window.addEventListener('popstate', () => {
|
||||
window.dispatchEvent(new Event('locationchange'));
|
||||
});
|
||||
})();
|
||||
|
||||
function getPromiseFromEvent(item, event) {
|
||||
return new Promise((resolve) => {
|
||||
const listener = () => {
|
||||
item.removeEventListener(event, listener);
|
||||
resolve();
|
||||
}
|
||||
item.addEventListener(event, listener);
|
||||
})
|
||||
}
|
||||
|
||||
// MIT Licensed
|
||||
// Author: jwilson8767
|
||||
function waitUntil(selector) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const el = document.querySelector(selector);
|
||||
if (el) {resolve(el);}
|
||||
new MutationObserver((mutationRecords, observer) => {
|
||||
// Query for elements matching the specified selector
|
||||
Array.from(document.querySelectorAll(selector)).forEach((element) => {
|
||||
resolve(element);
|
||||
//Once we have resolved we don't need the observer anymore.
|
||||
observer.disconnect();
|
||||
});
|
||||
})
|
||||
.observe(document.documentElement, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function sex(sex) {
|
||||
return sex // Sex
|
||||
}
|
||||
|
||||
function rand(list) {
|
||||
return list == undefined ? undefined : list[list.length*Math.random()|0]
|
||||
}
|
||||
|
||||
function audioplay(obj) {
|
||||
obj.play().catch(
|
||||
()=>{
|
||||
getPromiseFromEvent(window,'click').then(
|
||||
()=>{audio.play()}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function volumeChange (number) {
|
||||
localStorage.audiovolume = audio.volume = Math.round(audio.volume * 100 + (number%101))/100
|
||||
document.getElementById("user-audio-percentage").innerHTML = Math.floor(audio.volume * 100) + "%"
|
||||
}
|
||||
|
||||
function volumeSet(number) {
|
||||
localStorage.audiovolume = audio.volume = Math.round((number%101))/100
|
||||
document.getElementById("user-audio-percentage").innerHTML = Math.floor(audio.volume * 100) + "%"
|
||||
}
|
||||
|
||||
// Add rot music.
|
||||
audio = document.createElement("audio")
|
||||
audio.loop = true
|
||||
audio.id = "user-music"
|
||||
audio.style = "display:none;"
|
||||
localStorage.audiovolume = audio.volume = localStorage.audiovolume ? localStorage.audiovolume : 0.5
|
||||
// Rot player!
|
||||
|
||||
waitUntil("#music-controls").then ( (controls) => {
|
||||
document.getElementById("user-audio-percentage").innerHTML = Math.floor(localStorage.audiovolume * 100) + "%"
|
||||
controls.querySelector("#music-up").onclick = () => volumeChange(5)
|
||||
controls.querySelector("#music-down").onclick = () => volumeChange(-5)
|
||||
|
||||
})
|
||||
|
||||
waitUntil("#music-slider").then ( (slider) => {
|
||||
document.getElementById("user-audio-percentage").innerHTML = (slider.value = Math.floor(localStorage.audiovolume * 100)) + "%"
|
||||
slider.oninput = () => volumeSet(slider.value)
|
||||
})
|
||||
|
||||
waitUntil("#music-mute").then ( (box) => {
|
||||
audio.muted = box.checked = localStorage.audiomuted === "true"
|
||||
box.addEventListener('click', () => {
|
||||
localStorage.audiomuted = audio.muted = box.checked
|
||||
})
|
||||
});
|
||||
|
||||
let prev;
|
||||
let choice;
|
||||
|
||||
console.log("rot custom js loaded")
|
||||
addEventListener('locationchange',(event) => {
|
||||
f = window.location.toString().split("/").reverse();
|
||||
prev = choice
|
||||
choice = f[0].split('?')[0].split('#')[0]
|
||||
switch (choice) {
|
||||
case "about":
|
||||
//audio.src = document.getElementById("pageMusic").getAttribute("href")
|
||||
//console.log("audio sources set to " + audio.src)
|
||||
audio.src = "https://rape.pet/music/ItsFunny.mp3";
|
||||
audioplay(audio)
|
||||
break;
|
||||
default:
|
||||
if (prev == choice) return;
|
||||
audio.pause()
|
||||
// This line will cause a lot of errors.
|
||||
// Setting src to "" will cause any pending .play()s ot fail.
|
||||
audio.src = ""
|
||||
setTimeout( () => {
|
||||
posts = []
|
||||
if (document.getElementsByClassName("pin").length != 0) {
|
||||
posts = [...document.getElementsByClassName("pin")]
|
||||
posts = posts.filter( // I hate this. It keeps getting worse.
|
||||
(x) => x.nextElementSibling.querySelector(".StatusBody").querySelector(".text").innerHTML.toLowerCase().replace( /(<([^>]+)>)/ig, '').search(/profile theming post/ig) != -1
|
||||
)
|
||||
}
|
||||
if (posts.length != 0) {
|
||||
base = posts[0].nextElementSibling.querySelector(".StatusBody")
|
||||
music = base.querySelector(".audio-container")
|
||||
image = base.querySelector(".image-container")
|
||||
if (music) {
|
||||
audio.src = rand(music.children).src
|
||||
audio.id = "user-music"
|
||||
audioplay(audio)
|
||||
}
|
||||
if (image) {
|
||||
image = "url(" + rand(image.getElementsByTagName("img")).src + ")"
|
||||
document.getElementById("app-loaded").style.setProperty("--body-background-image",image)
|
||||
}
|
||||
} else if (document.getElementsByClassName("user-profile-field").length != 0) {
|
||||
// Music setup.
|
||||
fields = document.getElementsByClassName("user-profile-field-name")
|
||||
music = [...fields].filter( (x)=>x.title.toLowerCase().replace(/\s+/g, '')=="music" )
|
||||
if (music.length !=0) {
|
||||
music = rand(music).nextElementSibling.title
|
||||
audio.src = music
|
||||
audio.id = "user-music"
|
||||
audioplay(audio)
|
||||
}
|
||||
// Image setup. Unneeded. Pleroma sets it for you.
|
||||
//if (default_bg == undefined) {
|
||||
// default_bg = document.getElementById("app-loaded").style.getPropertyValue("--body-background-image")
|
||||
//}
|
||||
image = [...fields].filter( (x)=>x.title.toLowerCase().replace(/\s+/g, '')=="image" )
|
||||
if (image.length != 0) {
|
||||
image = image.at(0).nextElementSibling.title
|
||||
image = "url(" + image + ")"
|
||||
document.getElementById("app-loaded").style.setProperty("--body-background-image",image)
|
||||
}
|
||||
}
|
||||
|
||||
}, 1000);
|
||||
break;
|
||||
}
|
||||
});
|
Loading…
Reference in a new issue