Fix preview bar not being recreated

This commit is contained in:
Ajay 2021-12-28 12:52:48 -05:00 committed by Michael C
parent 7f374f0f86
commit 9b152a5525
No known key found for this signature in database
GPG key ID: FFB04FB3B878B7B4

View file

@ -87,6 +87,7 @@ const playerButtons: Record<string, {button: HTMLButtonElement, image: HTMLImage
// Direct Links after the config is loaded
utils.wait(() => Config.config !== null, 1000, 1).then(() => videoIDChange(getYouTubeVideoID(document)));
addPageListeners();
addHotkeyListener();
//the amount of times the sponsor lookup has retried
@ -377,7 +378,7 @@ function createPreviewBar(): void {
];
for (const selector of progressElementSelectors) {
const el = document.querySelector<HTMLElement>(selector);
const el = findValidElement(document.querySelectorAll(selector));
if (el) {
previewBar = new PreviewBar(el, onMobileYouTube, onInvidious);
@ -550,6 +551,14 @@ function refreshVideoAttachments() {
setupVideoListeners();
setupSkipButtonControlBar();
}
// Create a new bar in the new video element
if (previewBar && !utils.findReferenceNode()?.contains(previewBar.container)) {
previewBar.remove();
previewBar = null;
createPreviewBar();
}
}
}
@ -1843,6 +1852,16 @@ function getSegmentsMessage(sponsorTimes: SponsorTime[]): string {
return sponsorTimesMessage;
}
function addPageListeners(): void {
const refreshListners = () => {
if (!isVisible(video)) {
refreshVideoAttachments();
}
};
document.addEventListener("yt-navigate-finish", refreshListners);
}
function addHotkeyListener(): void {
document.addEventListener("keydown", hotkeyListener);
}