mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
fix: apply fix from eslint
This commit is contained in:
@ -53,10 +53,16 @@ export default createPlugin({
|
||||
|
||||
const songImage = document.querySelector<HTMLImageElement>('#song-image');
|
||||
const songVideo = document.querySelector<HTMLDivElement>('#song-video');
|
||||
const image = songImage?.querySelector<HTMLImageElement>('yt-img-shadow > img');
|
||||
const video = await waitForElement<HTMLVideoElement>('.html5-video-container > video');
|
||||
const image = songImage?.querySelector<HTMLImageElement>(
|
||||
'yt-img-shadow > img',
|
||||
);
|
||||
const video = await waitForElement<HTMLVideoElement>(
|
||||
'.html5-video-container > video',
|
||||
);
|
||||
|
||||
const videoWrapper = document.querySelector('#song-video > .player-wrapper');
|
||||
const videoWrapper = document.querySelector(
|
||||
'#song-video > .player-wrapper',
|
||||
);
|
||||
|
||||
const injectBlurImage = () => {
|
||||
if (!songImage || !image) return null;
|
||||
@ -95,7 +101,9 @@ export default createPlugin({
|
||||
const blurCanvas = document.createElement('canvas');
|
||||
blurCanvas.classList.add('html5-blur-canvas');
|
||||
|
||||
const context = blurCanvas.getContext('2d', { willReadFrequently: true });
|
||||
const context = blurCanvas.getContext('2d', {
|
||||
willReadFrequently: true,
|
||||
});
|
||||
|
||||
/* effect */
|
||||
let lastEffectWorkId: number | null = null;
|
||||
@ -109,14 +117,18 @@ export default createPlugin({
|
||||
if (!context) return;
|
||||
|
||||
const width = this.qualityRatio;
|
||||
let height = Math.max(Math.floor((blurCanvas.height / blurCanvas.width) * width), 1,);
|
||||
let height = Math.max(
|
||||
Math.floor((blurCanvas.height / blurCanvas.width) * width),
|
||||
1,
|
||||
);
|
||||
if (!Number.isFinite(height)) height = width;
|
||||
if (!height) return;
|
||||
|
||||
context.globalAlpha = 1;
|
||||
if (lastImageData) {
|
||||
const frameOffset = (1 / this.buffer) * (1000 / this.interpolationTime);
|
||||
context.globalAlpha = 1 - (frameOffset * 2); // because of alpha value must be < 1
|
||||
const frameOffset =
|
||||
(1 / this.buffer) * (1000 / this.interpolationTime);
|
||||
context.globalAlpha = 1 - frameOffset * 2; // because of alpha value must be < 1
|
||||
context.putImageData(lastImageData, 0, 0);
|
||||
context.globalAlpha = frameOffset;
|
||||
}
|
||||
@ -137,7 +149,9 @@ export default createPlugin({
|
||||
if (newWidth === 0 || newHeight === 0) return;
|
||||
|
||||
blurCanvas.width = this.qualityRatio;
|
||||
blurCanvas.height = Math.floor((newHeight / newWidth) * this.qualityRatio);
|
||||
blurCanvas.height = Math.floor(
|
||||
(newHeight / newWidth) * this.qualityRatio,
|
||||
);
|
||||
|
||||
if (this.isFullscreen) blurCanvas.classList.add('fullscreen');
|
||||
else blurCanvas.classList.remove('fullscreen');
|
||||
@ -151,7 +165,10 @@ export default createPlugin({
|
||||
|
||||
/* hooking */
|
||||
let canvasInterval: NodeJS.Timeout | null = null;
|
||||
canvasInterval = setInterval(onSync, Math.max(1, Math.ceil(1000 / this.buffer)));
|
||||
canvasInterval = setInterval(
|
||||
onSync,
|
||||
Math.max(1, Math.ceil(1000 / this.buffer)),
|
||||
);
|
||||
|
||||
const onPause = () => {
|
||||
if (canvasInterval) clearInterval(canvasInterval);
|
||||
@ -159,7 +176,10 @@ export default createPlugin({
|
||||
};
|
||||
const onPlay = () => {
|
||||
if (canvasInterval) clearInterval(canvasInterval);
|
||||
canvasInterval = setInterval(onSync, Math.max(1, Math.ceil(1000 / this.buffer)));
|
||||
canvasInterval = setInterval(
|
||||
onSync,
|
||||
Math.max(1, Math.ceil(1000 / this.buffer)),
|
||||
);
|
||||
};
|
||||
songVideo.addEventListener('pause', onPause);
|
||||
songVideo.addEventListener('play', onPlay);
|
||||
@ -198,11 +218,20 @@ export default createPlugin({
|
||||
if (isPageOpen) {
|
||||
const isVideo = isVideoMode();
|
||||
if (!force) {
|
||||
if (this.lastMediaType === 'video' && this.lastVideoSource === video?.src) return false;
|
||||
if (this.lastMediaType === 'image' && this.lastImageSource === image?.src) return false;
|
||||
if (
|
||||
this.lastMediaType === 'video' &&
|
||||
this.lastVideoSource === video?.src
|
||||
)
|
||||
return false;
|
||||
if (
|
||||
this.lastMediaType === 'image' &&
|
||||
this.lastImageSource === image?.src
|
||||
)
|
||||
return false;
|
||||
}
|
||||
this.unregister?.();
|
||||
this.unregister = (isVideo ? injectBlurVideo() : injectBlurImage()) ?? null;
|
||||
this.unregister =
|
||||
(isVideo ? injectBlurVideo() : injectBlurImage()) ?? null;
|
||||
} else {
|
||||
this.unregister?.();
|
||||
this.unregister = null;
|
||||
|
||||
@ -1,14 +1,24 @@
|
||||
import { t } from "@/i18n";
|
||||
import { MenuContext } from "@/types/contexts";
|
||||
import { MenuItemConstructorOptions } from "electron";
|
||||
import { AmbientModePluginConfig } from "./types";
|
||||
import { MenuItemConstructorOptions } from 'electron';
|
||||
|
||||
import { t } from '@/i18n';
|
||||
import { MenuContext } from '@/types/contexts';
|
||||
import { AmbientModePluginConfig } from './types';
|
||||
|
||||
export interface menuParameters {
|
||||
getConfig: () => AmbientModePluginConfig | Promise<AmbientModePluginConfig>;
|
||||
setConfig: (conf: Partial<Omit<AmbientModePluginConfig, "enabled">>) => void | Promise<void>;
|
||||
setConfig: (
|
||||
conf: Partial<Omit<AmbientModePluginConfig, 'enabled'>>,
|
||||
) => void | Promise<void>;
|
||||
}
|
||||
|
||||
export const menu: (ctx: MenuContext<AmbientModePluginConfig>) => MenuItemConstructorOptions[] | Promise<MenuItemConstructorOptions[]> = async ({ getConfig, setConfig }: menuParameters) => {
|
||||
export const menu: (
|
||||
ctx: MenuContext<AmbientModePluginConfig>,
|
||||
) =>
|
||||
| MenuItemConstructorOptions[]
|
||||
| Promise<MenuItemConstructorOptions[]> = async ({
|
||||
getConfig,
|
||||
setConfig,
|
||||
}: menuParameters) => {
|
||||
const interpolationTimeList = [0, 500, 1000, 1500, 2000, 3000, 4000, 5000];
|
||||
const qualityList = [10, 25, 50, 100, 200, 500, 1000];
|
||||
const sizeList = [100, 110, 125, 150, 175, 200, 300];
|
||||
@ -107,4 +117,4 @@ export const menu: (ctx: MenuContext<AmbientModePluginConfig>) => MenuItemConstr
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
@ -7,4 +7,4 @@ export type AmbientModePluginConfig = {
|
||||
size: number;
|
||||
opacity: number;
|
||||
fullscreen: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user