Skip to content

Commit 1609995

Browse files
authored
Merge pull request ajayyy#2355 from FelixFourcolor/segment-list-default-tab
Add option to configure segment list default tab
2 parents e1b1894 + d0978bf commit 1609995

5 files changed

Lines changed: 34 additions & 7 deletions

File tree

public/_locales

public/options/options.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,17 @@
329329
</label>
330330
</div>
331331
</div>
332+
333+
<br />
334+
335+
<div data-type="selector" data-sync="segmentListDefaultTab">
336+
<label class="optionLabel" for="segmentListDefaultTab">__MSG_segmentListDefaultTab__:</label>
337+
338+
<select id="segmentListDefaultTab" class="selector-element optionsSelector">
339+
<option value="0">__MSG_SegmentsCap__</option>
340+
<option value="1">__MSG_Chapters__</option>
341+
</select>
342+
</div>
332343
</div>
333344

334345
<div data-type="toggle" data-sync="darkMode">

src/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as CompileConfig from "../config.json";
22
import * as invidiousList from "../ci/invidiouslist.json";
3-
import { Category, CategorySelection, CategorySkipOption, NoticeVisibilityMode, PreviewBarOption, SponsorTime, VideoID, SponsorHideType } from "./types";
3+
import { Category, CategorySelection, CategorySkipOption, NoticeVisibilityMode, PreviewBarOption, SponsorTime, VideoID, SponsorHideType, SegmentListDefaultTab } from "./types";
44
import { Keybind, ProtoConfig, keybindEquals } from "../maze-utils/src/config";
55
import { HashedValue } from "../maze-utils/src/hash";
66
import { Permission, AdvancedSkipRuleSet } from "./utils/skipRule";
@@ -10,6 +10,7 @@ interface SBConfig {
1010
isVip: boolean;
1111
permissions: Record<Category, Permission>;
1212
defaultCategory: Category;
13+
segmentListDefaultTab: SegmentListDefaultTab;
1314
renderSegmentsAsChapters: boolean;
1415
forceChannelCheck: boolean;
1516
minutesSaved: number;
@@ -337,6 +338,7 @@ const syncDefaults = {
337338
isVip: false,
338339
permissions: {},
339340
defaultCategory: "chooseACategory" as Category,
341+
segmentListDefaultTab: SegmentListDefaultTab.Segments,
340342
renderSegmentsAsChapters: false,
341343
forceChannelCheck: false,
342344
minutesSaved: 0,

src/popup/SegmentListComponent.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react";
2-
import { ActionType, SegmentUUID, SponsorHideType, SponsorTime, VideoID } from "../types";
2+
import { ActionType, SegmentListDefaultTab, SegmentUUID, SponsorHideType, SponsorTime, VideoID } from "../types";
33
import Config from "../config";
44
import { waitFor } from "../../maze-utils/src";
55
import { shortCategoryName } from "../utils/categoryUtils";
@@ -61,12 +61,21 @@ export const SegmentListComponent = (props: SegmentListComponentProps) => {
6161
}, [props.segments]);
6262

6363
React.useEffect(() => {
64-
if (hasSegments){
65-
setTab(SegmentListTab.Segments);
64+
const setTabBasedOnConfig = () => {
65+
const preferChapters = Config.config.segmentListDefaultTab === SegmentListDefaultTab.Chapters;
66+
if (preferChapters) {
67+
setTab(hasChapters ? SegmentListTab.Chapter : SegmentListTab.Segments);
68+
} else {
69+
setTab(hasSegments ? SegmentListTab.Segments : SegmentListTab.Chapter);
70+
}
71+
};
72+
73+
if (Config.isReady()) {
74+
setTabBasedOnConfig();
6675
} else {
67-
setTab(SegmentListTab.Chapter);
76+
waitFor(() => Config.isReady()).then(setTabBasedOnConfig);
6877
}
69-
}, [props.videoID, hasSegments]);
78+
}, [props.videoID, hasSegments, hasChapters]);
7079

7180
const segmentsWithNesting = React.useMemo(() => {
7281
const result: SegmentWithNesting[] = [];

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,9 @@ export enum NoticeVisibilityMode {
227227
MiniForAll = 2,
228228
FadedForAutoSkip = 3,
229229
FadedForAll = 4
230+
}
231+
232+
export enum SegmentListDefaultTab {
233+
Segments,
234+
Chapters,
230235
}

0 commit comments

Comments
 (0)