mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-13 23:17:05 +03:00
Move more thumbnail logic to lib
This commit is contained in:
14
package-lock.json
generated
14
package-lock.json
generated
@@ -27,7 +27,7 @@
|
|||||||
],
|
],
|
||||||
"license": "LGPL-3.0-or-later",
|
"license": "LGPL-3.0-or-later",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ajayyy/maze-utils": "1.1.10",
|
"@ajayyy/maze-utils": "1.1.11",
|
||||||
"content-scripts-register-polyfill": "^4.0.2",
|
"content-scripts-register-polyfill": "^4.0.2",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0"
|
"react-dom": "^18.2.0"
|
||||||
@@ -67,9 +67,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@ajayyy/maze-utils": {
|
"node_modules/@ajayyy/maze-utils": {
|
||||||
"version": "1.1.10",
|
"version": "1.1.11",
|
||||||
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.10.tgz",
|
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.11.tgz",
|
||||||
"integrity": "sha512-JjiPEloeq5WjvjAWIpVEI+5g/pjKEJNtx/uM2ujp9oiT05+c9wKJGqIEC1kb8UeoXSkqrIaKy6b5RMabdy/dRQ==",
|
"integrity": "sha512-hHXqKpPG92c8efvYYmYfjKHhoEaURLJEaK2URIaSAqmxYaFX46hdgyQ/DWMDRx1ffbi49uZ84fOwjFLsyhG5cw==",
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
"type": "individual",
|
"type": "individual",
|
||||||
@@ -13858,9 +13858,9 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ajayyy/maze-utils": {
|
"@ajayyy/maze-utils": {
|
||||||
"version": "1.1.10",
|
"version": "1.1.11",
|
||||||
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.10.tgz",
|
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.11.tgz",
|
||||||
"integrity": "sha512-JjiPEloeq5WjvjAWIpVEI+5g/pjKEJNtx/uM2ujp9oiT05+c9wKJGqIEC1kb8UeoXSkqrIaKy6b5RMabdy/dRQ=="
|
"integrity": "sha512-hHXqKpPG92c8efvYYmYfjKHhoEaURLJEaK2URIaSAqmxYaFX46hdgyQ/DWMDRx1ffbi49uZ84fOwjFLsyhG5cw=="
|
||||||
},
|
},
|
||||||
"@ampproject/remapping": {
|
"@ampproject/remapping": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "background.js",
|
"main": "background.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ajayyy/maze-utils": "1.1.10",
|
"@ajayyy/maze-utils": "1.1.11",
|
||||||
"content-scripts-register-polyfill": "^4.0.2",
|
"content-scripts-register-polyfill": "^4.0.2",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0"
|
"react-dom": "^18.2.0"
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ import { StorageChangesObject } from "@ajayyy/maze-utils/lib/config";
|
|||||||
import { findValidElement } from "@ajayyy/maze-utils/lib/dom"
|
import { findValidElement } from "@ajayyy/maze-utils/lib/dom"
|
||||||
import { getHash, HashedValue } from "@ajayyy/maze-utils/lib/hash";
|
import { getHash, HashedValue } from "@ajayyy/maze-utils/lib/hash";
|
||||||
import { generateUserID } from "@ajayyy/maze-utils/lib/setup";
|
import { generateUserID } from "@ajayyy/maze-utils/lib/setup";
|
||||||
import { setThumbnailListener, updateAll } from "@ajayyy/maze-utils/lib/thumbnailManagement";
|
import { updateAll } from "@ajayyy/maze-utils/lib/thumbnailManagement";
|
||||||
import { labelThumbnails, setupThumbnailPageLoadListener } from "./utils/thumbnails";
|
import { setupThumbnailListener } from "./utils/thumbnails";
|
||||||
import * as documentScript from "../dist/js/document.js";
|
import * as documentScript from "../dist/js/document.js";
|
||||||
|
|
||||||
const utils = new Utils();
|
const utils = new Utils();
|
||||||
@@ -113,8 +113,7 @@ setupVideoModule({
|
|||||||
resetValues,
|
resetValues,
|
||||||
documentScript
|
documentScript
|
||||||
}, () => Config);
|
}, () => Config);
|
||||||
setThumbnailListener(labelThumbnails);
|
setupThumbnailListener();
|
||||||
setupThumbnailPageLoadListener();
|
|
||||||
|
|
||||||
//the video id of the last preview bar update
|
//the video id of the last preview bar update
|
||||||
let lastPreviewBarUpdate: VideoID;
|
let lastPreviewBarUpdate: VideoID;
|
||||||
|
|||||||
@@ -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 { isOnInvidious, parseYouTubeVideoIDFromURL } from "@ajayyy/maze-utils/lib/video";
|
||||||
import Config from "../config";
|
import Config from "../config";
|
||||||
import { getVideoLabel } from "./videoLabels";
|
import { getVideoLabel } from "./videoLabels";
|
||||||
|
import { setThumbnailListener } from "@ajayyy/maze-utils/lib/thumbnailManagement";
|
||||||
|
|
||||||
export async function labelThumbnails(thumbnails: HTMLImageElement[]): Promise<void> {
|
export async function labelThumbnails(thumbnails: HTMLImageElement[]): Promise<void> {
|
||||||
await Promise.all(thumbnails.map((t) => labelThumbnail(t)));
|
await Promise.all(thumbnails.map((t) => labelThumbnail(t)));
|
||||||
@@ -109,23 +108,8 @@ function insertSBIconDefinition() {
|
|||||||
document.body.appendChild(container.children[0]);
|
document.body.appendChild(container.children[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setupThumbnailPageLoadListener(): void {
|
export function setupThumbnailListener(): void {
|
||||||
const onLoad = () => {
|
setThumbnailListener(labelThumbnails, () => {
|
||||||
insertSBIconDefinition();
|
insertSBIconDefinition();
|
||||||
|
}, () => Config.isReady());
|
||||||
// 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();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user