From 6b584f211191751e93efb8acf31291b443e86ffa Mon Sep 17 00:00:00 2001 From: Ajay Date: Thu, 2 Jun 2022 21:32:06 -0400 Subject: [PATCH] Faster popup loading on firefox --- src/popup.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/popup.ts b/src/popup.ts index 40f70bab..568b2436 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -56,9 +56,6 @@ async function runThePopup(messageListener?: MessageListener): Promise { const messageHandler = new MessageHandler(messageListener); localizeHtmlPage(); - await utils.wait(() => Config.config !== null && allowPopup === true, 5000, 5); - document.querySelector("body").style.removeProperty("visibility"); - type InputPageElements = { whitelistToggle?: HTMLInputElement, toggleSwitch?: HTMLInputElement, @@ -66,6 +63,15 @@ async function runThePopup(messageListener?: MessageListener): Promise { }; type PageElements = { [key: string]: HTMLElement } & InputPageElements + /** If true, the content script is in the process of creating a new segment. */ + let creatingSegment = false; + + //the start and end time pairs (2d) + let sponsorTimes: SponsorTime[] = []; + + //current video ID of this tab + let currentVideoID = null; + const PageElements: PageElements = {}; [ @@ -124,6 +130,10 @@ async function runThePopup(messageListener?: MessageListener): Promise { "sbCloseButton" ].forEach(id => PageElements[id] = document.getElementById(id)); + getSegmentsFromContentScript(false); + await utils.wait(() => Config.config !== null && allowPopup, 5000, 5); + document.querySelector("body").style.removeProperty("visibility"); + PageElements.sbCloseButton.addEventListener("click", () => { sendTabMessage({ message: "closePopup" @@ -166,15 +176,6 @@ async function runThePopup(messageListener?: MessageListener): Promise { PageElements.refreshSegmentsButton.addEventListener("click", refreshSegments); PageElements.sbPopupIconCopyUserID.addEventListener("click", async () => navigator.clipboard.writeText(await utils.getHash(Config.config.userID))); - /** If true, the content script is in the process of creating a new segment. */ - let creatingSegment = false; - - //the start and end time pairs (2d) - let sponsorTimes: SponsorTime[] = []; - - //current video ID of this tab - let currentVideoID = null; - //show proper disable skipping button const disableSkipping = Config.config.disableSkipping; if (disableSkipping != undefined && disableSkipping) { @@ -254,8 +255,6 @@ async function runThePopup(messageListener?: MessageListener): Promise { // Must be delayed so it only happens once loaded setTimeout(() => PageElements.sponsorblockPopup.classList.remove("preload"), 250); - getSegmentsFromContentScript(false); - function showDonateWidget(viewCount: number) { if (Config.config.showDonationLink && Config.config.donateClicked <= 0 && Config.config.showPopupDonationCount < 5 && viewCount < 50000 && !Config.config.isVip && Config.config.skipCount > 10) { @@ -287,13 +286,14 @@ async function runThePopup(messageListener?: MessageListener): Promise { }); } - function loadTabData(tabs, updating: boolean): void { + async function loadTabData(tabs, updating: boolean): Promise { if (!currentVideoID) { //this isn't a YouTube video then displayNoVideo(); return; } + await utils.wait(() => Config.config !== null, 5000, 10); sponsorTimes = Config.config.unsubmittedSegments[currentVideoID] ?? []; updateSegmentEditingUI();