mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-12 14:37:23 +03:00
Faster popup loading on firefox
This commit is contained in:
30
src/popup.ts
30
src/popup.ts
@@ -56,9 +56,6 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
const messageHandler = new MessageHandler(messageListener);
|
const messageHandler = new MessageHandler(messageListener);
|
||||||
localizeHtmlPage();
|
localizeHtmlPage();
|
||||||
|
|
||||||
await utils.wait(() => Config.config !== null && allowPopup === true, 5000, 5);
|
|
||||||
document.querySelector("body").style.removeProperty("visibility");
|
|
||||||
|
|
||||||
type InputPageElements = {
|
type InputPageElements = {
|
||||||
whitelistToggle?: HTMLInputElement,
|
whitelistToggle?: HTMLInputElement,
|
||||||
toggleSwitch?: HTMLInputElement,
|
toggleSwitch?: HTMLInputElement,
|
||||||
@@ -66,6 +63,15 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
};
|
};
|
||||||
type PageElements = { [key: string]: HTMLElement } & InputPageElements
|
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 = {};
|
const PageElements: PageElements = {};
|
||||||
|
|
||||||
[
|
[
|
||||||
@@ -124,6 +130,10 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
"sbCloseButton"
|
"sbCloseButton"
|
||||||
].forEach(id => PageElements[id] = document.getElementById(id));
|
].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", () => {
|
PageElements.sbCloseButton.addEventListener("click", () => {
|
||||||
sendTabMessage({
|
sendTabMessage({
|
||||||
message: "closePopup"
|
message: "closePopup"
|
||||||
@@ -166,15 +176,6 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
PageElements.refreshSegmentsButton.addEventListener("click", refreshSegments);
|
PageElements.refreshSegmentsButton.addEventListener("click", refreshSegments);
|
||||||
PageElements.sbPopupIconCopyUserID.addEventListener("click", async () => navigator.clipboard.writeText(await utils.getHash(Config.config.userID)));
|
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
|
//show proper disable skipping button
|
||||||
const disableSkipping = Config.config.disableSkipping;
|
const disableSkipping = Config.config.disableSkipping;
|
||||||
if (disableSkipping != undefined && disableSkipping) {
|
if (disableSkipping != undefined && disableSkipping) {
|
||||||
@@ -254,8 +255,6 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
// Must be delayed so it only happens once loaded
|
// Must be delayed so it only happens once loaded
|
||||||
setTimeout(() => PageElements.sponsorblockPopup.classList.remove("preload"), 250);
|
setTimeout(() => PageElements.sponsorblockPopup.classList.remove("preload"), 250);
|
||||||
|
|
||||||
getSegmentsFromContentScript(false);
|
|
||||||
|
|
||||||
function showDonateWidget(viewCount: number) {
|
function showDonateWidget(viewCount: number) {
|
||||||
if (Config.config.showDonationLink && Config.config.donateClicked <= 0 && Config.config.showPopupDonationCount < 5
|
if (Config.config.showDonationLink && Config.config.donateClicked <= 0 && Config.config.showPopupDonationCount < 5
|
||||||
&& viewCount < 50000 && !Config.config.isVip && Config.config.skipCount > 10) {
|
&& viewCount < 50000 && !Config.config.isVip && Config.config.skipCount > 10) {
|
||||||
@@ -287,13 +286,14 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadTabData(tabs, updating: boolean): void {
|
async function loadTabData(tabs, updating: boolean): Promise<void> {
|
||||||
if (!currentVideoID) {
|
if (!currentVideoID) {
|
||||||
//this isn't a YouTube video then
|
//this isn't a YouTube video then
|
||||||
displayNoVideo();
|
displayNoVideo();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await utils.wait(() => Config.config !== null, 5000, 10);
|
||||||
sponsorTimes = Config.config.unsubmittedSegments[currentVideoID] ?? [];
|
sponsorTimes = Config.config.unsubmittedSegments[currentVideoID] ?? [];
|
||||||
updateSegmentEditingUI();
|
updateSegmentEditingUI();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user