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