mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-12 22:47:18 +03:00
Add channel skip profiles
This commit is contained in:
@@ -11,7 +11,6 @@ interface SBConfig {
|
||||
permissions: Record<Category, Permission>;
|
||||
defaultCategory: Category;
|
||||
renderSegmentsAsChapters: boolean;
|
||||
whitelistedChannels: string[];
|
||||
forceChannelCheck: boolean;
|
||||
minutesSaved: number;
|
||||
skipCount: number;
|
||||
@@ -138,6 +137,20 @@ interface SBConfig {
|
||||
|
||||
export type VideoDownvotes = { segments: { uuid: HashedValue; hidden: SponsorHideType }[]; lastAccess: number };
|
||||
|
||||
export type ConfigurationID = string & { __configurationID: never };
|
||||
|
||||
export interface CustomConfiguration {
|
||||
name: string;
|
||||
categorySelections: CategorySelection[];
|
||||
showAutogeneratedChapters: boolean | null;
|
||||
autoSkipOnMusicVideos: boolean | null;
|
||||
skipNonMusicOnlyOnYoutubeMusic: boolean | null;
|
||||
muteSegments: boolean | null;
|
||||
fullVideoSegments: boolean | null;
|
||||
manualSkipOnFullVideo: boolean | null;
|
||||
minDuration: number | null;
|
||||
}
|
||||
|
||||
interface SBStorage {
|
||||
/* VideoID prefixes to UUID prefixes */
|
||||
downvotedSegments: Record<VideoID & HashedValue, VideoDownvotes>;
|
||||
@@ -149,6 +162,10 @@ interface SBStorage {
|
||||
/* Contains unsubmitted segments that the user has created. */
|
||||
unsubmittedSegments: Record<string, SponsorTime[]>;
|
||||
|
||||
channelSkipProfileIDs: Record<string, ConfigurationID>;
|
||||
skipProfileTemp: { time: number; configID: ConfigurationID } | null;
|
||||
skipProfiles: Record<ConfigurationID, CustomConfiguration>;
|
||||
|
||||
skipRules: AdvancedSkipRuleSet[];
|
||||
}
|
||||
|
||||
@@ -168,7 +185,38 @@ class ConfigClass extends ProtoConfig<SBConfig, SBStorage> {
|
||||
}
|
||||
}
|
||||
|
||||
function migrateOldSyncFormats(config: SBConfig) {
|
||||
function migrateOldSyncFormats(config: SBConfig, local: SBStorage) {
|
||||
if (config["whitelistedChannels"]) {
|
||||
// convert to skipProfiles
|
||||
const whitelistedChannels = config["whitelistedChannels"] as string[];
|
||||
const skipProfileID: ConfigurationID = "default-whitelist" as ConfigurationID;
|
||||
|
||||
local.skipProfiles[skipProfileID] = {
|
||||
name: chrome.i18n.getMessage("WhitelistedChannels"),
|
||||
categorySelections: config.categorySelections
|
||||
.filter((s) => !["exclusive_access", "chapter"].includes(s.name))
|
||||
.map(s => ({
|
||||
name: s.name,
|
||||
option: CategorySkipOption.ShowOverlay
|
||||
})),
|
||||
showAutogeneratedChapters: null,
|
||||
autoSkipOnMusicVideos: null,
|
||||
skipNonMusicOnlyOnYoutubeMusic: null,
|
||||
muteSegments: null,
|
||||
fullVideoSegments: null,
|
||||
manualSkipOnFullVideo: null,
|
||||
minDuration: null
|
||||
};
|
||||
local.skipProfiles = local.skipProfiles;
|
||||
|
||||
for (const channelID of whitelistedChannels) {
|
||||
local.channelSkipProfileIDs[channelID] = skipProfileID;
|
||||
}
|
||||
local.channelSkipProfileIDs = local.channelSkipProfileIDs;
|
||||
|
||||
chrome.storage.sync.remove("whitelistedChannels");
|
||||
}
|
||||
|
||||
if (!config["changeChapterColor"]) {
|
||||
config.barTypes["chapter"].color = "#ffd983";
|
||||
config["changeChapterColor"] = true;
|
||||
@@ -290,7 +338,6 @@ const syncDefaults = {
|
||||
permissions: {},
|
||||
defaultCategory: "chooseACategory" as Category,
|
||||
renderSegmentsAsChapters: false,
|
||||
whitelistedChannels: [],
|
||||
forceChannelCheck: false,
|
||||
minutesSaved: 0,
|
||||
skipCount: 0,
|
||||
@@ -506,7 +553,11 @@ const localDefaults = {
|
||||
alreadyInstalled: false,
|
||||
|
||||
unsubmittedSegments: {},
|
||||
skipRules: []
|
||||
skipRules: [],
|
||||
|
||||
channelSkipProfileIDs: {},
|
||||
skipProfiles: {},
|
||||
skipProfileTemp: null
|
||||
};
|
||||
|
||||
const Config = new ConfigClass(syncDefaults, localDefaults, migrateOldSyncFormats);
|
||||
@@ -529,7 +580,7 @@ export function generateDebugDetails(): string {
|
||||
output.config.serverAddress = (output.config.serverAddress === CompileConfig.serverAddress)
|
||||
? "Default server address" : "Custom server address";
|
||||
output.config.invidiousInstances = output.config.invidiousInstances.length;
|
||||
output.config.whitelistedChannels = output.config.whitelistedChannels.length;
|
||||
output.config.skipRules = output.config.skipRules.length;
|
||||
|
||||
return JSON.stringify(output, null, 4);
|
||||
}
|
||||
Reference in New Issue
Block a user