Move more thumbnail logic to lib

This commit is contained in:
Ajay 2023-03-24 19:07:26 -04:00
parent e1b30204ce
commit c2252af575
4 changed files with 15 additions and 32 deletions

14
package-lock.json generated
View file

@ -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",

View file

@ -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"

View file

@ -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;

View file

@ -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());
}