mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
improve waitForElement
This commit is contained in:
@@ -23,7 +23,6 @@ exports.stopApplication = function () {
|
||||
};
|
||||
|
||||
exports.getDocument = function (callback, ms) {
|
||||
if (!ms || ms < 1000) ms = 1000;
|
||||
const url = "http://" + (config.address || "localhost") + ":" + (config.port || "8080");
|
||||
jsdom.JSDOM.fromURL(url, { resources: "usable", runScripts: "dangerously" }).then((dom) => {
|
||||
dom.window.name = "jsdom";
|
||||
@@ -37,22 +36,22 @@ exports.getDocument = function (callback, ms) {
|
||||
});
|
||||
};
|
||||
|
||||
exports.waitForElement = function(selector) {
|
||||
return new Promise(resolve => {
|
||||
if (document.querySelector(selector)) {
|
||||
return resolve(document.querySelector(selector));
|
||||
exports.waitForElement = function (selector) {
|
||||
return new Promise((resolve) => {
|
||||
if (document.querySelector(selector) && document.querySelector(selector).value !== undefined) {
|
||||
return resolve(document.querySelector(selector));
|
||||
}
|
||||
|
||||
const observer = new MutationObserver(() => {
|
||||
if (document.querySelector(selector) && document.querySelector(selector).value !== undefined) {
|
||||
resolve(document.querySelector(selector));
|
||||
observer.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
const observer = new MutationObserver(() => {
|
||||
if (document.querySelector(selector)) {
|
||||
resolve(document.querySelector(selector));
|
||||
observer.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user