diff options
Diffstat (limited to 'src/config.ts')
-rw-r--r-- | src/config.ts | 128 |
1 files changed, 26 insertions, 102 deletions
diff --git a/src/config.ts b/src/config.ts index 6e7e4248..12b8ab27 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,14 +1,11 @@ import * as CompileConfig from "../config.json"; -import { CategorySelection, CategorySkipOption, PreviewBarOption, SponsorTime, StorageChangesObject, UnEncodedSegmentTimes as UnencodedSegmentTimes } from "./types"; - -import Utils from "./utils"; -const utils = new Utils(); +import { Category, CategorySelection, CategorySkipOption, PreviewBarOption, SponsorTime, StorageChangesObject, UnEncodedSegmentTimes as UnencodedSegmentTimes } from "./types"; interface SBConfig { userID: string, /** Contains unsubmitted segments that the user has created. */ segmentTimes: SBMap<string, SponsorTime[]>, - defaultCategory: string, + defaultCategory: Category, whitelistedChannels: string[], forceChannelCheck: boolean, skipKeybind: string, @@ -62,6 +59,8 @@ interface SBConfig { "preview-preview": PreviewBarOption, "music_offtopic": PreviewBarOption, "preview-music_offtopic": PreviewBarOption, + "highlight": PreviewBarOption, + "preview-highlight": PreviewBarOption, } } @@ -147,7 +146,7 @@ const Config: SBObject = { defaults: { userID: null, segmentTimes: new SBMap("segmentTimes"), - defaultCategory: "chooseACategory", + defaultCategory: "chooseACategory" as Category, whitelistedChannels: [], forceChannelCheck: false, skipKeybind: "Enter", @@ -182,7 +181,7 @@ const Config: SBObject = { autoHideInfoButton: true, categorySelections: [{ - name: "sponsor", + name: "sponsor" as Category, option: CategorySkipOption.AutoSkip }], @@ -247,6 +246,14 @@ const Config: SBObject = { "preview-music_offtopic": { color: "#a6634a", opacity: "0.7" + }, + "highlight": { + color: "#ff1684", + opacity: "0.7" + }, + "preview-highlight": { + color: "#9b044c", + opacity: "0.7" } } }, @@ -343,6 +350,17 @@ function fetchConfig(): Promise<void> { } function migrateOldFormats(config: SBConfig) { + if (!config["highlightCategoryAdded"] && !config.categorySelections.some((s) => s.name === "highlight")) { + config["highlightCategoryAdded"] = true; + + config.categorySelections.push({ + name: "highlight" as Category, + option: CategorySkipOption.ManualSkip + }); + + config.categorySelections = config.categorySelections; + } + if (config["askAboutUnlistedVideos"]) { chrome.storage.sync.remove("askAboutUnlistedVideos"); } @@ -356,7 +374,7 @@ function migrateOldFormats(config: SBConfig) { // Add a default skip option for preview category config.categorySelections.push({ - name: "preview", + name: "preview" as Category, option: CategorySkipOption.ManualSkip }); // Ensure it gets updated @@ -376,100 +394,6 @@ function migrateOldFormats(config: SBConfig) { } } - // Auto vote removal - if (config["autoUpvote"]) { - chrome.storage.sync.remove("autoUpvote"); - } - // mobileUpdateShowCount removal - if (config["mobileUpdateShowCount"] !== undefined) { - chrome.storage.sync.remove("mobileUpdateShowCount"); - } - // categoryUpdateShowCount removal - if (config["categoryUpdateShowCount"] !== undefined) { - chrome.storage.sync.remove("categoryUpdateShowCount"); - } - - // Channel URLS - if (config.whitelistedChannels.length > 0 && - (config.whitelistedChannels[0] == null || config.whitelistedChannels[0].includes("/"))) { - const channelURLFixer = async() => { - const newChannelList: string[] = []; - for (const item of config.whitelistedChannels) { - if (item != null) { - if (item.includes("/channel/")) { - newChannelList.push(item.split("/")[2]); - } else if (item.includes("/user/") && utils.isContentScript()) { - - - // Replace channel URL with channelID - const response = await utils.asyncRequestToCustomServer("GET", "https://sponsor.ajay.app/invidious/api/v1/channels/" + item.split("/")[2] + "?fields=authorId"); - - if (response.ok) { - newChannelList.push((JSON.parse(response.responseText)).authorId); - } else { - // Add it at the beginning so it gets converted later - newChannelList.unshift(item); - } - } else if (item.includes("/user/")) { - // Add it at the beginning so it gets converted later (The API can only be called in the content script due to CORS issues) - newChannelList.unshift(item); - } else { - newChannelList.push(item); - } - } - } - - config.whitelistedChannels = newChannelList; - } - - channelURLFixer(); - } - - // Check if off-topic category needs to be removed - for (let i = 0; i < config.categorySelections.length; i++) { - if (config.categorySelections[i].name === "offtopic") { - config.categorySelections.splice(i, 1); - // Call set listener - config.categorySelections = config.categorySelections; - break; - } - } - - // Migrate old "sponsorTimes" - if (config["sponsorTimes"]) { - let jsonData: unknown = config["sponsorTimes"]; - - // Check if data is stored in the old format for SBMap (a JSON string) - if (typeof jsonData === "string") { - try { - jsonData = JSON.parse(jsonData); - } catch(e) { - // Continue normally (out of this if statement) - } - } - - // Otherwise junk data - if (Array.isArray(jsonData)) { - const oldMap = new Map(jsonData); - oldMap.forEach((sponsorTimes: [number, number][], key) => { - const segmentTimes: SponsorTime[] = []; - for (const segment of sponsorTimes) { - segmentTimes.push({ - segment: segment, - category: "sponsor", - UUID: null - }); - } - - config.segmentTimes.rawSet(key, segmentTimes); - }); - - config.segmentTimes.update(); - } - - chrome.storage.sync.remove("sponsorTimes"); - } - // Remove some old unused options if (config["sponsorVideoID"] !== undefined) { chrome.storage.sync.remove("sponsorVideoID"); |