Skip to content

Commit

Permalink
Remove remaining chapter code from preview bar
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Mar 3, 2024
1 parent cd0d0e4 commit 171d2f6
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 66 deletions.
4 changes: 0 additions & 4 deletions public/content.css
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@
transform: translateY(2em) !important;
}

div:hover > .sponsorBlockChapterBar {
z-index: 41 !important;
}

/* */

.popup {
Expand Down
62 changes: 1 addition & 61 deletions src/js-components/previewBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ https://github.com/videosegments/videosegments/commits/f1e111bdfe231947800c6efdd

import Config from "../config";
import { ChapterVote } from "../render/ChapterVote";
import { ActionType, Category, SegmentContainer, SponsorHideType, SponsorSourceType, SponsorTime } from "../types";
import { ActionType, Category, SponsorHideType, SponsorSourceType, SponsorTime } from "../types";
import { DEFAULT_CATEGORY, shortCategoryName } from "../utils/categoryUtils";

const TOOLTIP_VISIBLE_CLASS = 'sponsorCategoryTooltipVisible';
Expand All @@ -24,11 +24,6 @@ export interface PreviewBarSegment {
selectedSegment?: boolean;
}

interface ChapterGroup extends SegmentContainer {
originalDuration: number;
actionType: ActionType;
}

class PreviewBar {
container: HTMLUListElement;
categoryTooltip?: HTMLDivElement;
Expand All @@ -44,19 +39,8 @@ class PreviewBar {
segments: PreviewBarSegment[] = [];
existingChapters: PreviewBarSegment[] = [];
videoDuration = 0;
lastChapterUpdate = 0;

// For chapter bar
hoveredSection: HTMLElement;
customChaptersBar: HTMLElement;
chaptersBarSegments: PreviewBarSegment[];
chapterVote: ChapterVote;
originalChapterBar: HTMLElement;
originalChapterBarBlocks: NodeListOf<HTMLElement>;
chapterMargin: number;
lastRenderedSegments: PreviewBarSegment[];
unfilteredChapterGroups: ChapterGroup[];
chapterGroups: ChapterGroup[];

constructor(parent: HTMLElement, chapterVote: ChapterVote, test=false) {
if (test) return;
Expand Down Expand Up @@ -145,15 +129,7 @@ class PreviewBar {
this.container.removeChild(this.container.firstChild);
}

if (this.customChaptersBar) this.customChaptersBar.style.display = "none";
this.originalChapterBar?.style?.removeProperty("display");
this.chapterVote?.setVisibility(false);

document.querySelectorAll(`.sponsorBlockChapterBar`).forEach((e) => {
if (e !== this.customChaptersBar) {
e.remove();
}
});
}

set(segments: PreviewBarSegment[], videoDuration: number): void {
Expand Down Expand Up @@ -356,42 +332,6 @@ class PreviewBar {
* Decimal to time or time to decimal
*/
decimalTimeConverter(value: number, isTime: boolean): number {
if (this.originalChapterBarBlocks?.length > 1 && this.existingChapters.length === this.originalChapterBarBlocks?.length) {
// Parent element to still work when display: none
const totalPixels = this.originalChapterBar.parentElement.clientWidth;
let pixelOffset = 0;
let lastCheckedChapter = -1;
for (let i = 0; i < this.originalChapterBarBlocks.length; i++) {
const chapterElement = this.originalChapterBarBlocks[i];
const widthPixels = parseFloat(chapterElement.style.width.replace("px", ""));

const marginPixels = chapterElement.style.marginRight ? parseFloat(chapterElement.style.marginRight.replace("px", "")) : 0;
if ((isTime && value >= this.existingChapters[i].segment[1])
|| (!isTime && value >= (pixelOffset + widthPixels + marginPixels) / totalPixels)) {
pixelOffset += widthPixels + marginPixels;
lastCheckedChapter = i;
} else {
break;
}
}

// The next chapter is the one we are currently inside of
const latestChapter = this.existingChapters[lastCheckedChapter + 1];
if (latestChapter) {
const latestWidth = parseFloat(this.originalChapterBarBlocks[lastCheckedChapter + 1].style.width.replace("px", ""));
const latestChapterDuration = latestChapter.segment[1] - latestChapter.segment[0];

if (isTime) {
const percentageInCurrentChapter = (value - latestChapter.segment[0]) / latestChapterDuration;
const sizeOfCurrentChapter = latestWidth / totalPixels;
return Math.min(1, ((pixelOffset / totalPixels) + (percentageInCurrentChapter * sizeOfCurrentChapter)));
} else {
const percentageInCurrentChapter = (value * totalPixels - pixelOffset) / latestWidth;
return Math.max(0, latestChapter.segment[0] + (percentageInCurrentChapter * latestChapterDuration));
}
}
}

if (isTime) {
return Math.min(1, value / this.videoDuration);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/pageCleaner.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function cleanPage() {
// For live-updates
if (document.readyState === "complete") {
for (const element of document.querySelectorAll("#categoryPillParent, .playerButton, .sponsorThumbnailLabel, #submissionNoticeContainer, .sponsorSkipNoticeContainer, #sponsorBlockPopupContainer, .skipButtonControlBarContainer, #previewbar, .sponsorBlockChapterBar")) {
for (const element of document.querySelectorAll("#categoryPillParent, .playerButton, .sponsorThumbnailLabel, #submissionNoticeContainer, .sponsorSkipNoticeContainer, #sponsorBlockPopupContainer, .skipButtonControlBarContainer, #previewbar")) {
element.remove();
}
}
Expand Down

0 comments on commit 171d2f6

Please sign in to comment.