mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
fix(precise-volume): fix precise-volume plugin
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
import { overrideListener } from './override';
|
||||
|
||||
import { debounce } from '../../providers/decorators';
|
||||
|
||||
import { YoutubePlayer } from '../../types/youtube-player';
|
||||
|
||||
import type { YoutubePlayer } from '../../types/youtube-player';
|
||||
import type { ConfigType } from '../../config/dynamic';
|
||||
|
||||
function $<E extends Element = Element>(selector: string) {
|
||||
@ -12,6 +13,8 @@ let api: YoutubePlayer;
|
||||
let options: ConfigType<'precise-volume'>;
|
||||
|
||||
export default (_options: ConfigType<'precise-volume'>) => {
|
||||
overrideListener();
|
||||
|
||||
options = _options;
|
||||
document.addEventListener('apiLoaded', (e) => {
|
||||
api = e.detail;
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
/* what */
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
|
||||
import is from 'electron-is';
|
||||
|
||||
const ignored = {
|
||||
id: ['volume-slider', 'expand-volume-slider'],
|
||||
types: ['mousewheel', 'keydown', 'keyup'],
|
||||
};
|
||||
} as const;
|
||||
|
||||
function overrideAddEventListener() {
|
||||
// YO WHAT ARE YOU DOING NOW?!?!
|
||||
@ -15,20 +13,20 @@ function overrideAddEventListener() {
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
Element.prototype._addEventListener = Element.prototype.addEventListener;
|
||||
// Override addEventListener to Ignore specific events in volume-slider
|
||||
Element.prototype.addEventListener = function (type: string, listener: (event: Event) => void, useCapture = false) {
|
||||
Element.prototype.addEventListener = function(type: string, listener: (event: Event) => void, useCapture = false) {
|
||||
if (!(
|
||||
ignored.id.includes(this.id)
|
||||
&& ignored.types.includes(type)
|
||||
)) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
||||
(this as any)._addEventListener(type, listener, useCapture);
|
||||
} else if (is.dev()) {
|
||||
} else if (window.electronIs.dev()) {
|
||||
console.log(`Ignoring event: "${this.id}.${type}()"`);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default () => {
|
||||
export const overrideListener = () => {
|
||||
overrideAddEventListener();
|
||||
// Restore original function after finished loading to avoid keeping Element.prototype altered
|
||||
window.addEventListener('load', () => {
|
||||
@ -4,7 +4,6 @@ import is from 'electron-is';
|
||||
import config from './config';
|
||||
|
||||
import adblockerPreload from './plugins/adblocker/preload';
|
||||
import preciseVolumePreload from './plugins/precise-volume/preload';
|
||||
|
||||
import type { ConfigType, OneOfDefaultConfigKey } from './config/dynamic';
|
||||
|
||||
@ -18,7 +17,6 @@ export type PluginMapper<Type extends 'renderer' | 'preload' | 'backend'> = {
|
||||
|
||||
const preloadPlugins: PluginMapper<'preload'> = {
|
||||
'adblocker': adblockerPreload,
|
||||
'precise-volume': preciseVolumePreload,
|
||||
};
|
||||
|
||||
const enabledPluginNameAndOptions = config.plugins.getEnabled();
|
||||
|
||||
Reference in New Issue
Block a user