diff --git a/public/index.html b/public/index.html index 2adb82e37..3e241dde0 100644 --- a/public/index.html +++ b/public/index.html @@ -2,6 +2,7 @@ + diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index 91e8cf3d9..0c52af3f3 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -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); diff --git a/public/scripts/extensions/expressions/index.js b/public/scripts/extensions/expressions/index.js index 93b2254fc..9f7518021 100644 --- a/public/scripts/extensions/expressions/index.js +++ b/public/scripts/extensions/expressions/index.js @@ -297,7 +297,7 @@ function onClickExpressionImage() { const html = `
- +
`; $('body').append(html); }