From 8cec0e7a6542daec4f6081a5a0d73c7c54ed5ce6 Mon Sep 17 00:00:00 2001 From: eight Date: Mon, 20 May 2019 20:01:50 +0800 Subject: [PATCH] Change: report updatable after the install button is prepared --- content/install-hook-userstyles.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) 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); + }); } }