mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-09 13:07:05 +03:00
Changes to preview bar
This commit is contained in:
@@ -761,7 +761,7 @@ function getYouTubeVideoID(url: string) {
|
|||||||
*/
|
*/
|
||||||
function updatePreviewBarPositionMobile(parent: HTMLElement) {
|
function updatePreviewBarPositionMobile(parent: HTMLElement) {
|
||||||
if (document.getElementById("previewbar") === null) {
|
if (document.getElementById("previewbar") === null) {
|
||||||
previewBar.updatePosition(parent);
|
previewBar.createElement(parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
This is based on code from VideoSegments.
|
Parts of this are inspired from code from VideoSegments, but rewritten and under the LGPLv3 license
|
||||||
https://github.com/videosegments/videosegments/commits/f1e111bdfe231947800c6efdd51f62a4e7fef4d4/segmentsbar/segmentsbar.js
|
https://github.com/videosegments/videosegments/commits/f1e111bdfe231947800c6efdd51f62a4e7fef4d4/segmentsbar/segmentsbar.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class PreviewBar {
|
|||||||
this.onMobileYouTube = onMobileYouTube;
|
this.onMobileYouTube = onMobileYouTube;
|
||||||
this.onInvidious = onInvidious;
|
this.onInvidious = onInvidious;
|
||||||
|
|
||||||
this.updatePosition(parent);
|
this.createElement(parent);
|
||||||
|
|
||||||
this.setupHoverText();
|
this.setupHoverText();
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ class PreviewBar {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePosition(parent: HTMLElement): void {
|
createElement(parent: HTMLElement): void {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
|
||||||
if (this.onMobileYouTube) {
|
if (this.onMobileYouTube) {
|
||||||
@@ -148,16 +148,6 @@ class PreviewBar {
|
|||||||
this.parent.prepend(this.container);
|
this.parent.prepend(this.container);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: call on config changes
|
|
||||||
updateColor(segmentType: string, color: string, opacity: number): void {
|
|
||||||
const bars = <NodeListOf<HTMLElement>> document.querySelectorAll('[data-vs-segment-type=' + segmentType + ']');
|
|
||||||
|
|
||||||
for (const bar of bars) {
|
|
||||||
bar.style.backgroundColor = color;
|
|
||||||
bar.style.opacity = String(opacity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
clear(): void {
|
clear(): void {
|
||||||
this.videoDuration = 0;
|
this.videoDuration = 0;
|
||||||
this.segments = [];
|
this.segments = [];
|
||||||
@@ -169,7 +159,6 @@ class PreviewBar {
|
|||||||
|
|
||||||
set(segments: PreviewBarSegment[], videoDuration: number): void {
|
set(segments: PreviewBarSegment[], videoDuration: number): void {
|
||||||
this.clear();
|
this.clear();
|
||||||
|
|
||||||
if (!segments) return;
|
if (!segments) return;
|
||||||
|
|
||||||
this.segments = segments;
|
this.segments = segments;
|
||||||
@@ -195,7 +184,7 @@ class PreviewBar {
|
|||||||
bar.setAttribute('data-vs-segment-type', barSegmentType);
|
bar.setAttribute('data-vs-segment-type', barSegmentType);
|
||||||
|
|
||||||
bar.style.backgroundColor = Config.config.barTypes[barSegmentType]?.color;
|
bar.style.backgroundColor = Config.config.barTypes[barSegmentType]?.color;
|
||||||
if (!this.onMobileYouTube) bar.style.opacity = Config.config.barTypes[barSegmentType].opacity;
|
if (!this.onMobileYouTube) bar.style.opacity = Config.config.barTypes[barSegmentType]?.opacity;
|
||||||
|
|
||||||
bar.style.position = "absolute";
|
bar.style.position = "absolute";
|
||||||
bar.style.width = this.timeToPercentage(segment[1] - segment[0]);
|
bar.style.width = this.timeToPercentage(segment[1] - segment[0]);
|
||||||
|
|||||||
Reference in New Issue
Block a user