fix selection bugs

This commit is contained in:
uwaa 2025-01-11 08:05:32 +00:00
parent f7773a3f1c
commit 2537532a98

72
rot.js
View file

@ -117,12 +117,14 @@
console.log("Applying main theme");
setMusic(null);
//<meta name="pageMusic" content="/assets/music.ogg">
waitUntilSpecial('meta[name="pageMusic"]').then((pageMusic) => {
setMusic(pageMusic.content);
playMusic();
return true;
});
//<a id="pageMusic" href="/assets/music.ogg"></a>
waitUntilSpecial("#pageMusic").then((pageMusic) => {
setMusic(pageMusic.getAttribute("href"));
playMusic();
@ -134,6 +136,7 @@
console.log("Applying user theme");
setMusic(null);
//Configure by post
waitUntilSpecial(".pin").then((pinnedPost) => {
if (pinnedPost.nextElementSibling
.querySelector(".StatusBody")
@ -143,45 +146,44 @@
.search(/profile theming post/ig) == -1)
return false;
let ptp = pinnedPost.nextElementSibling.querySelector(".StatusBody");
if (ptp) {
//Configured by post
let musicContainer = ptp.querySelector(".audio-container")
if (musicContainer)
setMusic(rand(musicContainer.children).src);
else
setMusic(null);
let imageContainer = ptp.querySelector(".image-container")
if (imageContainer)
setImage(rand(imageContainer.getElementsByTagName("img")).src);
else
setImage(null);
return true;
} else {
const ptp = pinnedPost.nextElementSibling.querySelector(".StatusBody");
if (!ptp)
return false;
}
}, observers);
const musicContainer = ptp.querySelector(".audio-container")
if (musicContainer)
setMusic(rand(musicContainer.children).src);
else
setMusic(null);
const imageContainer = ptp.querySelector(".image-container")
if (imageContainer)
setImage(rand(imageContainer.getElementsByTagName("img")).src);
else
setImage(null);
return musicContainer || imageContainer;
});
//Configure by fields
waitUntilSpecial(".user-profile-field-name").then(() => {
let fields = [...document.getElementsByClassName("user-profile-field-name")]
if (fields.length != 0) {
//Configured by fields
let musicFields = fields.filter((x) => x.title.toLowerCase().replace(/\s+/g, '') == "music")
if (musicFields.length > 0)
setMusic(rand(musicFields).nextElementSibling.title);
else
setMusic(null);
let imageFields = fields.filter((x) => x.title.toLowerCase().replace(/\s+/g, '') == "image")
if (imageFields.length > 0)
setImage(rand(imageFields).nextElementSibling.title);
else
setImage(null);
return true;
} else {
const fields = [...document.getElementsByClassName("user-profile-field-name")]
if (fields.length == 0)
return false;
}
const musicFields = fields.filter((x) => x.title.toLowerCase().replace(/\s+/g, '') == "music")
if (musicFields.length > 0)
setMusic(rand(musicFields).nextElementSibling.title);
else
setMusic(null);
const imageFields = fields.filter((x) => x.title.toLowerCase().replace(/\s+/g, '') == "image")
if (imageFields.length > 0)
setImage(rand(imageFields).nextElementSibling.title);
else
setImage(null);
return musicFields.length > 0 || imageFields.length > 0;
});
}