mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-11 05:57:07 +03:00
Fix animation when chapter bar is recreated
This commit is contained in:
@@ -291,7 +291,7 @@ class PreviewBar {
|
|||||||
progressBar.prepend(newChapterBar);
|
progressBar.prepend(newChapterBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateChapterAllMutation(chapterBar, progressBar);
|
this.updateChapterAllMutation(chapterBar, progressBar, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private setupChapterSection(section: HTMLElement, duration: number): void {
|
private setupChapterSection(section: HTMLElement, duration: number): void {
|
||||||
@@ -331,17 +331,17 @@ class PreviewBar {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateChapterAllMutation(originalChapterBar: HTMLElement, progressBar: HTMLElement): void {
|
private updateChapterAllMutation(originalChapterBar: HTMLElement, progressBar: HTMLElement, firstUpdate = false): void {
|
||||||
const elements = originalChapterBar.querySelectorAll(".ytp-progress-list > *");
|
const elements = originalChapterBar.querySelectorAll(".ytp-progress-list > *");
|
||||||
const changes: Record<string, HTMLElement> = {};
|
const changes: Record<string, HTMLElement> = {};
|
||||||
for (const element of elements) {
|
for (const element of elements) {
|
||||||
changes[element.classList[0]] = element as HTMLElement;
|
changes[element.classList[0]] = element as HTMLElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateChapterMutation(changes, progressBar);
|
this.updateChapterMutation(changes, progressBar, firstUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateChapterMutation(changes: Record<string, HTMLElement>, progressBar: HTMLElement): void {
|
private updateChapterMutation(changes: Record<string, HTMLElement>, progressBar: HTMLElement, firstUpdate = false): void {
|
||||||
// Go through each newly generated chapter bar and update the width based on changes array
|
// Go through each newly generated chapter bar and update the width based on changes array
|
||||||
if (this.customChaptersBar) {
|
if (this.customChaptersBar) {
|
||||||
// Width reached so far in decimal percent
|
// Width reached so far in decimal percent
|
||||||
@@ -369,6 +369,12 @@ class PreviewBar {
|
|||||||
customChangedElement.style.transform =
|
customChangedElement.style.transform =
|
||||||
`scaleX(${Math.max(0, Math.min(1 - calculatedLeft,
|
`scaleX(${Math.max(0, Math.min(1 - calculatedLeft,
|
||||||
(transformScale - cursor) / sectionWidthDecimal - calculatedLeft))}`;
|
(transformScale - cursor) / sectionWidthDecimal - calculatedLeft))}`;
|
||||||
|
|
||||||
|
// Prevent transition from occuring
|
||||||
|
if (firstUpdate) {
|
||||||
|
customChangedElement.style.transition = "none";
|
||||||
|
setTimeout(() => customChangedElement.style.transition = "inherit", 50);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customChangedElement.className = changedElement.className;
|
customChangedElement.className = changedElement.className;
|
||||||
|
|||||||
Reference in New Issue
Block a user