mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 03:41:46 +00:00
feat(disable-autoplay): add apply once, resolve #9
This commit is contained in:
@ -113,6 +113,9 @@ const defaultConfig = {
|
|||||||
'lyric-genius': {
|
'lyric-genius': {
|
||||||
romanizedLyrics: false,
|
romanizedLyrics: false,
|
||||||
},
|
},
|
||||||
|
'disable-autoplay': {
|
||||||
|
applyOnce: false,
|
||||||
|
},
|
||||||
'discord': {
|
'discord': {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
autoReconnect: true, // If enabled, will try to reconnect to discord every 5 seconds after disconnecting or failing to connect
|
autoReconnect: true, // If enabled, will try to reconnect to discord every 5 seconds after disconnecting or failing to connect
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
export default () => {
|
import type { ConfigType } from '../../config/dynamic';
|
||||||
|
|
||||||
|
export default (options: ConfigType<'disable-autoplay'>) => {
|
||||||
const timeUpdateListener = (e: Event) => {
|
const timeUpdateListener = (e: Event) => {
|
||||||
if (e.target instanceof HTMLVideoElement) {
|
if (e.target instanceof HTMLVideoElement) {
|
||||||
e.target.pause();
|
e.target.pause();
|
||||||
@ -6,13 +8,16 @@ export default () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
document.addEventListener('apiLoaded', (apiEvent) => {
|
document.addEventListener('apiLoaded', (apiEvent) => {
|
||||||
apiEvent.detail.addEventListener('videodatachange', (name: string) => {
|
const eventListener = (name: string) => {
|
||||||
|
if (options.applyOnce) {
|
||||||
|
apiEvent.detail.removeEventListener('videodatachange', eventListener);
|
||||||
|
}
|
||||||
|
|
||||||
if (name === 'dataloaded') {
|
if (name === 'dataloaded') {
|
||||||
apiEvent.detail.pauseVideo();
|
apiEvent.detail.pauseVideo();
|
||||||
document.querySelector<HTMLVideoElement>('video')?.addEventListener('timeupdate', timeUpdateListener);
|
document.querySelector<HTMLVideoElement>('video')?.addEventListener('timeupdate', timeUpdateListener, { once: true });
|
||||||
} else {
|
|
||||||
document.querySelector<HTMLVideoElement>('video')?.removeEventListener('timeupdate', timeUpdateListener);
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
apiEvent.detail.addEventListener('videodatachange', eventListener);
|
||||||
}, { once: true, passive: true });
|
}, { once: true, passive: true });
|
||||||
};
|
};
|
||||||
|
|||||||
20
plugins/disable-autoplay/menu.ts
Normal file
20
plugins/disable-autoplay/menu.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { BrowserWindow } from 'electron';
|
||||||
|
|
||||||
|
import { setMenuOptions } from '../../config/plugins';
|
||||||
|
|
||||||
|
import { MenuTemplate } from '../../menu';
|
||||||
|
|
||||||
|
import type { ConfigType } from '../../config/dynamic';
|
||||||
|
|
||||||
|
export default (_: BrowserWindow, options: ConfigType<'disable-autoplay'>): MenuTemplate => [
|
||||||
|
{
|
||||||
|
label: 'Applies only on startup',
|
||||||
|
type: 'checkbox',
|
||||||
|
checked: options.applyOnce,
|
||||||
|
click() {
|
||||||
|
setMenuOptions('disable-autoplay', {
|
||||||
|
applyOnce: !options.applyOnce,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
Reference in New Issue
Block a user