diff --git a/rot.js b/rot.js index 9850409..516e64f 100644 --- a/rot.js +++ b/rot.js @@ -117,12 +117,14 @@ console.log("Applying main theme"); setMusic(null); + // waitUntilSpecial('meta[name="pageMusic"]').then((pageMusic) => { setMusic(pageMusic.content); playMusic(); return true; }); + // 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; }); }