mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 13:37:04 +03:00
Fix chapter imports when not in focus
This commit is contained in:
@@ -56,6 +56,7 @@ let sponsorDataFound = false;
|
|||||||
//the actual sponsorTimes if loaded and UUIDs associated with them
|
//the actual sponsorTimes if loaded and UUIDs associated with them
|
||||||
let sponsorTimes: SponsorTime[] = [];
|
let sponsorTimes: SponsorTime[] = [];
|
||||||
let existingChaptersImported = false;
|
let existingChaptersImported = false;
|
||||||
|
let importingChaptersWaitingForFocus = false;
|
||||||
// List of open skip notices
|
// List of open skip notices
|
||||||
const skipNotices: SkipNotice[] = [];
|
const skipNotices: SkipNotice[] = [];
|
||||||
let activeSkipKeybindElement: ToggleSkippable = null;
|
let activeSkipKeybindElement: ToggleSkippable = null;
|
||||||
@@ -1146,7 +1147,17 @@ async function sponsorsLookup(keepOldSubmissions = true) {
|
|||||||
|
|
||||||
function importExistingChapters(wait: boolean) {
|
function importExistingChapters(wait: boolean) {
|
||||||
if (!existingChaptersImported) {
|
if (!existingChaptersImported) {
|
||||||
waitFor(() => getVideo()?.duration && getExistingChapters(getVideoID(), getVideo().duration),
|
const waitCondition = () => getVideo()?.duration && getExistingChapters(getVideoID(), getVideo().duration);
|
||||||
|
|
||||||
|
if (!waitCondition() && wait && !document.hasFocus() && !importingChaptersWaitingForFocus) {
|
||||||
|
importingChaptersWaitingForFocus = true;
|
||||||
|
const listener = () => {
|
||||||
|
importExistingChapters(wait);
|
||||||
|
window.removeEventListener("focus", listener);
|
||||||
|
};
|
||||||
|
window.addEventListener("focus", listener);
|
||||||
|
} else {
|
||||||
|
waitFor(waitCondition,
|
||||||
wait ? 15000 : 0, 400, (c) => c?.length > 0).then((chapters) => {
|
wait ? 15000 : 0, 400, (c) => c?.length > 0).then((chapters) => {
|
||||||
if (!existingChaptersImported && chapters?.length > 0) {
|
if (!existingChaptersImported && chapters?.length > 0) {
|
||||||
sponsorTimes = (sponsorTimes ?? []).concat(...chapters).sort((a, b) => a.segment[0] - b.segment[0]);
|
sponsorTimes = (sponsorTimes ?? []).concat(...chapters).sort((a, b) => a.segment[0] - b.segment[0]);
|
||||||
@@ -1156,6 +1167,7 @@ function importExistingChapters(wait: boolean) {
|
|||||||
}).catch(() => {}); // eslint-disable-line @typescript-eslint/no-empty-function
|
}).catch(() => {}); // eslint-disable-line @typescript-eslint/no-empty-function
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getEnabledActionTypes(forceFullVideo = false): ActionType[] {
|
function getEnabledActionTypes(forceFullVideo = false): ActionType[] {
|
||||||
const actionTypes = [ActionType.Skip, ActionType.Poi, ActionType.Chapter];
|
const actionTypes = [ActionType.Skip, ActionType.Poi, ActionType.Chapter];
|
||||||
|
|||||||
Reference in New Issue
Block a user