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

@ -2,6 +2,7 @@
<html> <html>
<head> <head>
<base href="/">
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, viewport-fit=cover, initial-scale=1, maximum-scale=1.0, user-scalable=no"> <meta name="viewport" content="width=device-width, viewport-fit=cover, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes">

View File

@ -60,11 +60,46 @@ const observer = new MutationObserver(function (mutations) {
} else if (mutation.target.parentNode === SelectedCharacterTab) { } else if (mutation.target.parentNode === SelectedCharacterTab) {
setTimeout(RA_CountCharTokens, 200); setTimeout(RA_CountCharTokens, 200);
} }
}); });
}); });
observer.observe(document.documentElement, observerConfig); 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. //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. //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("sheld"));
dragElement(document.getElementById("left-nav-panel")); dragElement(document.getElementById("left-nav-panel"));
dragElement(document.getElementById("right-nav-panel")); dragElement(document.getElementById("right-nav-panel"));
setTimeout(function () {
dragElement(document.getElementById("expression-holder"))
}, 2000);
function dragElement(elmnt) { function dragElement(elmnt) {
@ -460,6 +493,7 @@ function dragElement(elmnt) {
// --------------------------------------------------- // ---------------------------------------------------
$("document").ready(function () { $("document").ready(function () {
// initial status check // initial status check
setTimeout(RA_checkOnlineStatus, 100); setTimeout(RA_checkOnlineStatus, 100);

View File

@ -297,7 +297,7 @@ function onClickExpressionImage() {
const html = ` const html = `
<div id="expression-holder" class="expression-holder"> <div id="expression-holder" class="expression-holder">
<div id="expression-holderheader" class="fa-solid fa-grip drag-grabber"></div> <div id="expression-holderheader" class="fa-solid fa-grip drag-grabber"></div>
<img class="expression"> <img id="expression-image" class="expression">
</div>`; </div>`;
$('body').append(html); $('body').append(html);
} }