From 80493a38e143e5d903d6b857db37eb5a760a9ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zero=20=E2=9D=A4?= Date: Sun, 29 Oct 2023 22:36:34 -0500 Subject: [PATCH] Fix manage button click handler --- js/main.js | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/js/main.js b/js/main.js index 8ca2a73..90821b6 100644 --- a/js/main.js +++ b/js/main.js @@ -574,23 +574,11 @@ function surroundElement(elementSelector, surroundElementName) } // Blocks until the element is visible -function waitForElementVisibility(selector, timeout = 5000, all = false) +function waitForElementVisibility(selector, timeout = 5000, all = false, expr = false) { let start = Date.now(); - if (!all) - { - let element = document.querySelector(selector); - while (element == null || element.offsetParent === null) - { - if (Date.now() - start > timeout) - { - throw new Error(`Timed out waiting for element ${selector} to appear.`); - } - element = document.querySelector(selector); - } - } - else - { + if (all) + { let elements = document.querySelectorAll(selector); while (elements.length == 0) { @@ -601,6 +589,31 @@ function waitForElementVisibility(selector, timeout = 5000, all = false) elements = document.querySelectorAll(selector); } } + else if (expr) + { + let xExpr = document.createExpression(selector); + let elements = xExpr.evaluate(document, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE); + while (elements.snapshotLength == 0) + { + if (Date.now() - start > timeout) + { + throw new Error(`Timed out waiting for element ${selector} to appear.`); + } + elements = xExpr.evaluate(document, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE); + } + } + else + { + let element = document.querySelector(selector); + while (element == null || element.offsetParent === null) + { + if (Date.now() - start > timeout) + { + throw new Error(`Timed out waiting for element ${selector} to appear.`); + } + element = document.querySelector(selector); + } + } } async function initCuteness() { @@ -881,6 +894,8 @@ async function initCuteness() { subtree: true }); + waitForElementVisibility("//div[contains(concat(' ', @class, ' '), ' comfy-menu ')]/button[contains(., 'Manager')]", 5000, false, true); + // Inside .cute-comfy-menu, find a button with the innertext of "Manage" var manageBtn = Array.from(document.querySelectorAll(".cute-comfy-menu button")).filter((btn) => btn.innerText.toLowerCase().includes("manager")); if (manageBtn.length > 0)