diff --git a/builded.user.js b/builded.user.js index d455199..43ab98f 100644 --- a/builded.user.js +++ b/builded.user.js @@ -14,7 +14,26 @@ // @require https://github.com/pie6k/jquery.initialize/raw/refs/heads/master/jquery.initialize.min.js // @run-at document-end // ==/UserScript== +function waitForElm(selector) { + return new Promise(resolve => { + if (document.querySelector(selector)) { + return resolve(document.querySelector(selector)); + } + const observer = new MutationObserver(mutations => { + if (document.querySelector(selector)) { + observer.disconnect(); + resolve(document.querySelector(selector)); + } + }); + + // If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336 + observer.observe(document.body, { + childList: true, + subtree: true + }); + }); +} let settings_HTML = `
If you see this text, the userscript successfully rendered the settings page.
`; @@ -42,7 +61,10 @@ if (location.host == "www.guilded.gg") { console.info("Guilded.GG detected."); $.initialize('.DesktopOptionsControl-persistent-menu', function() { console.info("Settings opened!") - $(this).innerHTML += settings_entry; + waitForElm('.PersistentActionMenuSection-container').then((elm) => { + console.log('Injecting Builded settings...'); + $(this).innerHTML += settings_entry; + }); }); } else { document.body.innerHTML += settings_HTML;