Change: report updatable after the install button is prepared

This commit is contained in:
eight 2019-05-20 20:01:50 +08:00
parent a194f7eb26
commit 8cec0e7a65

View File

@ -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);
});
}
}