diff --git a/src/youtube.ts b/src/youtube.ts index 44cb76b..cbcd845 100644 --- a/src/youtube.ts +++ b/src/youtube.ts @@ -28,16 +28,16 @@ function peertubeify(query: string) { browser.runtime.sendMessage({ query }).then(async video => { - removeVideoLink(); - const options = await browser.storage.local.get(); const openInOriginalInstance = _.getOr(true, 'openInOriginalInstance', options); const searchInstance = _.getOr(constants.defaultInstance, 'searchInstance', options); const url = watchURL(openInOriginalInstance ? video.account.host : searchInstance, video.uuid); const link = videoLink(url, video); + + removeVideoLink(); document.querySelector('ytd-app').appendChild(link); - }); + }).catch(removeVideoLink); } const throttledPeertubify = _.throttle(1000, peertubeify); @@ -58,7 +58,7 @@ observer.observe(document.body, { subtree: true, }) -function htmlToElement(html: string) : Element { +function htmlToElement(html: string): Element { const template = document.createElement('template'); template.innerHTML = html.trim(); return template.content.firstElementChild;