diff options
author | Ajay <[email protected]> | 2023-03-10 03:49:01 -0500 |
---|---|---|
committer | Ajay <[email protected]> | 2023-03-10 03:49:01 -0500 |
commit | 758f0b7526f5e3774fa723433c7cbc47d21badd5 (patch) | |
tree | 852a26f8f71d61aade3af35f07faabeb594f447d /src/content.ts | |
parent | 3ace3b96506fbcb4648e36129bfc6e735d73d811 (diff) | |
download | SponsorBlock-758f0b7526f5e3774fa723433c7cbc47d21badd5.tar.gz SponsorBlock-758f0b7526f5e3774fa723433c7cbc47d21badd5.zip |
Show Full-Video Labels on thumbnails
Co-authored-by: mini-bomba <[email protected]>
Diffstat (limited to 'src/content.ts')
-rw-r--r-- | src/content.ts | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/content.ts b/src/content.ts index 6e719c31..b73be606 100644 --- a/src/content.ts +++ b/src/content.ts @@ -43,11 +43,16 @@ import { StorageChangesObject } from "@ajayyy/maze-utils/lib/config"; import { findValidElement } from "@ajayyy/maze-utils/lib/dom" import { getHash, HashedValue } from "@ajayyy/maze-utils/lib/hash"; import { generateUserID } from "@ajayyy/maze-utils/lib/setup"; +import { setThumbnailListener, updateAll } from "@ajayyy/maze-utils/lib/thumbnailManagement"; +import { labelThumbnails, setupThumbnailPageLoadListener } from "./utils/thumbnails"; const utils = new Utils(); -// Hack to get the CSS loaded on permission-based sites (Invidious) -utils.wait(() => Config.isReady(), 5000, 10).then(addCSS); +utils.wait(() => Config.isReady(), 5000, 10).then(() => { + // Hack to get the CSS loaded on permission-based sites (Invidious) + addCSS(); + setCategoryColorCSSVariables(); +}); const skipBuffer = 0.003; @@ -108,6 +113,8 @@ setupVideoModule({ }, resetValues }, () => Config); +setThumbnailListener(labelThumbnails); +setupThumbnailPageLoadListener(); //the video id of the last preview bar update let lastPreviewBarUpdate: VideoID; @@ -332,6 +339,12 @@ function contentConfigUpdateListener(changes: StorageChangesObject) { case "categorySelections": sponsorsLookup(); break; + case "barTypes": + setCategoryColorCSSVariables(); + break; + case "fullVideoSegments": + updateAll(); + break; } } } @@ -2466,4 +2479,25 @@ function checkForPreloadedSegment() { Config.config.unsubmittedSegments[getVideoID()] = sponsorTimesSubmitting; Config.forceSyncUpdate("unsubmittedSegments"); } +} + +// Generate and inject a stylesheet that creates CSS variables with configured category colors +function setCategoryColorCSSVariables() { + let styleContainer = document.getElementById("sbCategoryColorStyle"); + if (!styleContainer) { + styleContainer = document.createElement("style"); + styleContainer.id = "sbCategoryColorStyle"; + document.head.appendChild(styleContainer) + } + + let css = ":root {" + for (const [category, config] of Object.entries(Config.config.barTypes)) { + css += `--sb-category-${category}: ${config.color};`; + + const luminance = GenericUtils.getLuminance(config.color); + css += `--sb-category-text-${category}: ${luminance > 128 ? "black" : "white"};`; + } + css += "}"; + + styleContainer.innerText = css; }
\ No newline at end of file |