added <base> tag to HTML

added observer to wait for expressions before enabling drag
This commit is contained in:
RossAscends
2023-04-19 22:58:59 +09:00
parent b55a9f4e13
commit 4df04f3b3f
3 changed files with 39 additions and 4 deletions

View File

@@ -60,11 +60,46 @@ const observer = new MutationObserver(function (mutations) {
} else if (mutation.target.parentNode === SelectedCharacterTab) {
setTimeout(RA_CountCharTokens, 200);
}
});
});
observer.observe(document.documentElement, observerConfig);
/**
* Wait for an element before resolving a promise
* @param {String} querySelector - Selector of element to wait for
* @param {Integer} timeout - Milliseconds to wait before timing out, or 0 for no timeout
*/
function waitForElement(querySelector, timeout) {
return new Promise((resolve, reject) => {
var timer = false;
if (document.querySelectorAll(querySelector).length) return resolve();
const observer = new MutationObserver(() => {
if (document.querySelectorAll(querySelector).length) {
observer.disconnect();
if (timer !== false) clearTimeout(timer);
return resolve();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
if (timeout) timer = setTimeout(() => {
observer.disconnect();
reject();
}, timeout);
});
}
waitForElement("#expression-image", 10000).then(function () {
console.log("expression image loaded, now draggable.");
dragElement(document.getElementById("expression-holder"));
}).catch(() => {
console.log("expression holder not loaded yet");
});
//RossAscends: Added function to format dates used in files and chat timestamps to a humanized format.
//Mostly I wanted this to be for file names, but couldn't figure out exactly where the filename save code was as everything seemed to be connected.
@@ -315,9 +350,7 @@ function OpenNavPanels() {
dragElement(document.getElementById("sheld"));
dragElement(document.getElementById("left-nav-panel"));
dragElement(document.getElementById("right-nav-panel"));
setTimeout(function () {
dragElement(document.getElementById("expression-holder"))
}, 2000);
function dragElement(elmnt) {
@@ -460,6 +493,7 @@ function dragElement(elmnt) {
// ---------------------------------------------------
$("document").ready(function () {
// initial status check
setTimeout(RA_checkOnlineStatus, 100);