diff --git a/content/install-hook-userstyles.js b/content/install-hook-userstyles.js index 32835ece..c0fd8f70 100644 --- a/content/install-hook-userstyles.js +++ b/content/install-hook-userstyles.js @@ -93,9 +93,26 @@ }); } + function prepareInstallButton() { + return new Promise(resolve => { + const observer = new MutationObserver(check); + observer.observe(document.documentElement, { + childList: true, + subtree: true + }); + check(); + + function check() { + if (document.querySelector('#install_style_button')) { + resolve(); + observer.disconnect(); + } + } + }); + } + function reportUpdatable(isUpdatable) { - // USO doesn't bind these listeners immediately - setTimeout(() => { + prepareInstallButton().then(() => { sendEvent({ type: isUpdatable ? 'styleCanBeUpdatedChrome' @@ -104,7 +121,7 @@ updateUrl: installedStyle.updateUrl }, }); - }, 300); + }); } }