diff options
author | Ajay <[email protected]> | 2022-09-02 14:38:49 -0400 |
---|---|---|
committer | Ajay <[email protected]> | 2022-09-02 14:38:49 -0400 |
commit | c8e2bb0c1303b507cb8872eddb9b5bc83eae7b51 (patch) | |
tree | a209fafaea4a790c188dfe2a7945124bfe6ee45a /src/options.ts | |
parent | 39ed7ea83cd80635b294b06c86ece85bac3d3d61 (diff) | |
download | SponsorBlock-c8e2bb0c1303b507cb8872eddb9b5bc83eae7b51.tar.gz SponsorBlock-c8e2bb0c1303b507cb8872eddb9b5bc83eae7b51.zip |
Auto update hidden categories when redeemed
Diffstat (limited to 'src/options.ts')
-rw-r--r-- | src/options.ts | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/options.ts b/src/options.ts index 8d66834c..c9596abb 100644 --- a/src/options.ts +++ b/src/options.ts @@ -14,9 +14,13 @@ import UnsubmittedVideos from "./render/UnsubmittedVideos"; import KeybindComponent from "./components/options/KeybindComponent"; import { showDonationLink } from "./utils/configUtils"; import { localizeHtmlPage } from "./utils/pageUtils"; +import { StorageChangesObject } from "./types"; const utils = new Utils(); let embed = false; +const categoryChoosers: CategoryChooser[] = []; +const unsubmittedVideos: UnsubmittedVideos[] = []; + window.addEventListener('DOMContentLoaded', init); async function init() { @@ -291,10 +295,10 @@ async function init() { break; } case "react-CategoryChooserComponent": - new CategoryChooser(optionsElements[i]); + categoryChoosers.push(new CategoryChooser(optionsElements[i])); break; case "react-UnsubmittedVideosComponent": - new UnsubmittedVideos(optionsElements[i]) + unsubmittedVideos.push(new UnsubmittedVideos(optionsElements[i])); break; } } @@ -352,10 +356,8 @@ async function shouldHideOption(element: Element): Promise<boolean> { /** * Called when the config is updated - * - * @param {String} element */ -function optionsConfigUpdateListener() { +function optionsConfigUpdateListener(changes: StorageChangesObject) { const optionsContainer = document.getElementById("options"); const optionsElements = optionsContainer.querySelectorAll("*"); @@ -364,9 +366,16 @@ function optionsConfigUpdateListener() { case "display": updateDisplayElement(<HTMLElement> optionsElements[i]) break; - case "react-UnsubmittedVideosComponent": - new UnsubmittedVideos(optionsElements[i]) - break; + } + } + + if (changes.categorySelections || changes.payments) { + for (const chooser of categoryChoosers) { + chooser.update(); + } + } else if (changes.unsubmittedSegments) { + for (const chooser of unsubmittedVideos) { + chooser.update(); } } } @@ -662,4 +671,4 @@ function copyDebugOutputToClipboard() { function isIncognitoAllowed(): Promise<boolean> { return new Promise((resolve) => chrome.extension.isAllowedIncognitoAccess(resolve)); -} +}
\ No newline at end of file |