diff options
author | Ajay <[email protected]> | 2023-03-24 19:07:26 -0400 |
---|---|---|
committer | Ajay <[email protected]> | 2023-03-24 19:07:26 -0400 |
commit | c2252af575ed425e9256b8fc10ba413a81390d50 (patch) | |
tree | 69cc82eab79e354f2481953ca761a122ec35837f | |
parent | e1b30204ce7062e565f6c522ac0639ef918f9bdb (diff) | |
download | SponsorBlock-c2252af575ed425e9256b8fc10ba413a81390d50.tar.gz SponsorBlock-c2252af575ed425e9256b8fc10ba413a81390d50.zip |
Move more thumbnail logic to lib
-rw-r--r-- | package-lock.json | 14 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/content.ts | 7 | ||||
-rw-r--r-- | src/utils/thumbnails.ts | 24 |
4 files changed, 15 insertions, 32 deletions
diff --git a/package-lock.json b/package-lock.json index 891e1389..66da680e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,7 @@ ], "license": "LGPL-3.0-or-later", "dependencies": { - "@ajayyy/maze-utils": "1.1.10", + "@ajayyy/maze-utils": "1.1.11", "content-scripts-register-polyfill": "^4.0.2", "react": "^18.2.0", "react-dom": "^18.2.0" @@ -67,9 +67,9 @@ } }, "node_modules/@ajayyy/maze-utils": { - "version": "1.1.10", - "resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.10.tgz", - "integrity": "sha512-JjiPEloeq5WjvjAWIpVEI+5g/pjKEJNtx/uM2ujp9oiT05+c9wKJGqIEC1kb8UeoXSkqrIaKy6b5RMabdy/dRQ==", + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.11.tgz", + "integrity": "sha512-hHXqKpPG92c8efvYYmYfjKHhoEaURLJEaK2URIaSAqmxYaFX46hdgyQ/DWMDRx1ffbi49uZ84fOwjFLsyhG5cw==", "funding": [ { "type": "individual", @@ -13858,9 +13858,9 @@ }, "dependencies": { "@ajayyy/maze-utils": { - "version": "1.1.10", - "resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.10.tgz", - "integrity": "sha512-JjiPEloeq5WjvjAWIpVEI+5g/pjKEJNtx/uM2ujp9oiT05+c9wKJGqIEC1kb8UeoXSkqrIaKy6b5RMabdy/dRQ==" + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.11.tgz", + "integrity": "sha512-hHXqKpPG92c8efvYYmYfjKHhoEaURLJEaK2URIaSAqmxYaFX46hdgyQ/DWMDRx1ffbi49uZ84fOwjFLsyhG5cw==" }, "@ampproject/remapping": { "version": "2.2.0", diff --git a/package.json b/package.json index 5d126a9b..c678efa8 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "", "main": "background.js", "dependencies": { - "@ajayyy/maze-utils": "1.1.10", + "@ajayyy/maze-utils": "1.1.11", "content-scripts-register-polyfill": "^4.0.2", "react": "^18.2.0", "react-dom": "^18.2.0" diff --git a/src/content.ts b/src/content.ts index 548e1eea..207c16af 100644 --- a/src/content.ts +++ b/src/content.ts @@ -41,8 +41,8 @@ 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"; +import { updateAll } from "@ajayyy/maze-utils/lib/thumbnailManagement"; +import { setupThumbnailListener } from "./utils/thumbnails"; import * as documentScript from "../dist/js/document.js"; const utils = new Utils(); @@ -113,8 +113,7 @@ setupVideoModule({ resetValues, documentScript }, () => Config); -setThumbnailListener(labelThumbnails); -setupThumbnailPageLoadListener(); +setupThumbnailListener(); //the video id of the last preview bar update let lastPreviewBarUpdate: VideoID; diff --git a/src/utils/thumbnails.ts b/src/utils/thumbnails.ts index 8b8ed266..a54530a6 100644 --- a/src/utils/thumbnails.ts +++ b/src/utils/thumbnails.ts @@ -1,8 +1,7 @@ -import { waitFor } from "@ajayyy/maze-utils"; -import { newThumbnails } from "@ajayyy/maze-utils/lib/thumbnailManagement"; import { isOnInvidious, parseYouTubeVideoIDFromURL } from "@ajayyy/maze-utils/lib/video"; import Config from "../config"; import { getVideoLabel } from "./videoLabels"; +import { setThumbnailListener } from "@ajayyy/maze-utils/lib/thumbnailManagement"; export async function labelThumbnails(thumbnails: HTMLImageElement[]): Promise<void> { await Promise.all(thumbnails.map((t) => labelThumbnail(t))); @@ -109,23 +108,8 @@ function insertSBIconDefinition() { document.body.appendChild(container.children[0]); } -export function setupThumbnailPageLoadListener(): void { - const onLoad = () => { +export function setupThumbnailListener(): void { + setThumbnailListener(labelThumbnails, () => { insertSBIconDefinition(); - - // Label thumbnails on load if on Invidious (wait for variable initialization before checking) - waitFor(() => isOnInvidious() !== null).then(() => { - if (isOnInvidious()) newThumbnails(); - }); - }; - - if (document.readyState === "complete") { - onLoad(); - } else { - window.addEventListener("load", onLoad); - } - - waitFor(() => Config.isReady(), 5000, 10).then(() => { - newThumbnails(); - }); + }, () => Config.isReady()); }
\ No newline at end of file |