From 171d2f6471f5548224e349af51c94f7e85fd4252 Mon Sep 17 00:00:00 2001 From: HanYaodong Date: Sun, 3 Mar 2024 22:13:30 +0800 Subject: [PATCH] Remove remaining chapter code from preview bar --- public/content.css | 4 --- src/js-components/previewBar.ts | 62 +-------------------------------- src/utils/pageCleaner.ts | 2 +- 3 files changed, 2 insertions(+), 66 deletions(-) diff --git a/public/content.css b/public/content.css index 197dc993..5fd5c176 100644 --- a/public/content.css +++ b/public/content.css @@ -119,10 +119,6 @@ transform: translateY(2em) !important; } -div:hover > .sponsorBlockChapterBar { - z-index: 41 !important; -} - /* */ .popup { diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts index 9aae8bd0..c5dff29a 100644 --- a/src/js-components/previewBar.ts +++ b/src/js-components/previewBar.ts @@ -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'; @@ -24,11 +24,6 @@ export interface PreviewBarSegment { selectedSegment?: boolean; } -interface ChapterGroup extends SegmentContainer { - originalDuration: number; - actionType: ActionType; -} - class PreviewBar { container: HTMLUListElement; categoryTooltip?: HTMLDivElement; @@ -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; - chapterMargin: number; - lastRenderedSegments: PreviewBarSegment[]; - unfilteredChapterGroups: ChapterGroup[]; - chapterGroups: ChapterGroup[]; constructor(parent: HTMLElement, chapterVote: ChapterVote, test=false) { if (test) return; @@ -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 { @@ -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 { diff --git a/src/utils/pageCleaner.ts b/src/utils/pageCleaner.ts index 0d2ad2b9..dbc7059c 100644 --- a/src/utils/pageCleaner.ts +++ b/src/utils/pageCleaner.ts @@ -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(); } }