fix profile theming music if its the second pin

This commit is contained in:
uwaa 2025-01-14 15:00:16 +00:00
parent 7184f11baa
commit dd12f90306

48
rot.js
View file

@ -94,27 +94,26 @@
//Registers a mutation observer for an element. Upon triggering and the callback
//returning true, observation ceases. All observers are disconnected and the array is cleared.
const observers = [];
function waitUntilSpecial(selector) {
return new Promise((resolve, reject) => {
const newObserver = new MutationObserver((mutationRecords, observer) => {
// Query for elements matching the specified selector
Array.from(document.querySelectorAll(selector)).forEach((element) => {
//Callback
if (!resolve(element))
return;
function waitUntilSpecial(selector, callback) {
const newObserver = new MutationObserver((mutationRecords, observer) => {
// Query for elements matching the specified selector
Array.from(document.querySelectorAll(selector)).forEach((element) => {
//Callback
if (!callback(element))
return;
//Clean up
for (const o of observers)
o.disconnect();
observers.length = 0;
});
});
observers.push(newObserver);
newObserver.observe(document.documentElement, {
childList: true,
subtree: true
//Clean up
console.log("Cleaning up");
for (const o of observers)
o.disconnect();
observers.length = 0;
});
});
observers.push(newObserver);
newObserver.observe(document.documentElement, {
childList: true,
subtree: true
});
}
//Theme application
@ -124,14 +123,14 @@
setMusic(null);
//<meta name="pageMusic" content="/assets/music.ogg">
waitUntilSpecial('meta[name="pageMusic"]').then((pageMusic) => {
waitUntilSpecial('meta[name="pageMusic"]', (pageMusic) => {
setMusic(pageMusic.content);
playMusic();
return true;
});
//<a id="pageMusic" href="/assets/music.ogg"></a>
waitUntilSpecial("#pageMusic").then((pageMusic) => {
waitUntilSpecial("#pageMusic", (pageMusic) => {
setMusic(pageMusic.getAttribute("href"));
playMusic();
return true;
@ -143,7 +142,8 @@
setMusic(null);
//Configure by post
waitUntilSpecial(".pin").then((pinnedPost) => {
waitUntilSpecial(".pin", (pinnedPost) => {
console.log(pinnedPost);
if (pinnedPost.nextElementSibling
.querySelector(".StatusBody")
.querySelector(".text")
@ -156,13 +156,13 @@
if (!ptp)
return false;
const musicContainer = ptp.querySelector(".audio-container")
const musicContainer = ptp.querySelector(".audio-container");
if (musicContainer)
setMusic(rand(musicContainer.children).src);
else
setMusic(null);
const imageContainer = ptp.querySelector(".image-container")
const imageContainer = ptp.querySelector(".image-container");
if (imageContainer)
setImage(rand(imageContainer.getElementsByTagName("img")).src);
else
@ -172,7 +172,7 @@
});
//Configure by fields
waitUntilSpecial(".user-profile-field-name").then(() => {
waitUntilSpecial(".user-profile-field-name", () => {
const fields = [...document.getElementsByClassName("user-profile-field-name")]
if (fields.length == 0)
return false;