diff --git a/rot.js b/rot.js index 00734c7..5e56add 100644 --- a/rot.js +++ b/rot.js @@ -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); // - waitUntilSpecial('meta[name="pageMusic"]').then((pageMusic) => { + waitUntilSpecial('meta[name="pageMusic"]', (pageMusic) => { setMusic(pageMusic.content); playMusic(); return true; }); // - 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;