diff --git a/package.json b/package.json index bbf6845..9458922 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "yt-defaulter", "author": "GooseOb", - "version": "1.11.16", + "version": "1.11.17", "repository": { "type": "git", "url": "git+https://github.com/GooseOb/YT-Defaulter.git" diff --git a/src/menu/value.ts b/src/menu/value.ts index fbdbf6a..a362def 100644 --- a/src/menu/value.ts +++ b/src/menu/value.ts @@ -37,5 +37,4 @@ export const fixPosition = () => { const { y, height, width, left } = btn.getBoundingClientRect(); element.style.top = y + height + 8 + 'px'; element.style.left = left + width - menuWidth + 'px'; - console.log(element.style.left); }; diff --git a/src/player/value-setters.ts b/src/player/value-setters.ts index f0beecb..d3f6f40 100644 --- a/src/player/value-setters.ts +++ b/src/player/value-setters.ts @@ -5,51 +5,45 @@ import * as menu from './menu'; import type { YtSettingName } from './types'; type Comparator = (target: string, current: string) => boolean; -const comparators: { readonly [P in YtSettingName]: Comparator } = { +const comparators = { // assuming the search is from the top [QUALITY]: (target, current) => +target >= parseInt(current) && (config.value.flags.enhancedBitrate || !current.toLowerCase().includes('premium')), [SPEED]: (target, current) => target === current, -}; -type ValueSetterHelpers = { - _ytSettingItem(settingName: YtSettingName, value: string): void; -}; -type ValueSetters = { - [P in config.Setting]: (value: Required[P]) => void; +} satisfies { readonly [P in YtSettingName]: Comparator }; + +const setYT = (settingName: YtSettingName) => (value: string) => { + const isOpen = menu.isOpen(); + const compare = comparators[settingName]; + const btn = menu.findInItem(settingName, (btn) => + compare(value, btn.textContent) + ); + if (btn) { + btn.click(); + } + menu.setOpen(isOpen); }; -export const valueSetters: ValueSetters & ValueSetterHelpers = { - _ytSettingItem(settingName, value) { - const isOpen = menu.isOpen(); - const compare = comparators[settingName]; - const btn = menu.findInItem(settingName, (btn) => - compare(value, btn.textContent) - ); - if (btn) { - btn.click(); - menu.setOpen(isOpen); - } - }, - speed(value) { - this._ytSettingItem(SPEED, plr.isSpeedApplied ? plr.speedNormal : value); +export const valueSetters = { + speed: (value) => { + setYT(SPEED)(plr.isSpeedApplied ? plr.speedNormal : value); plr.toggleSpeed(); }, - customSpeed(value) { + customSpeed: (value) => { try { plr.video.playbackRate = plr.isSpeedApplied ? 1 : +value; + plr.toggleSpeed(); } catch { logger.outOfRange('Custom speed'); - return; } - plr.toggleSpeed(); }, - subtitles(value) { + subtitles: (value) => { if (plr.subtitlesBtn.ariaPressed !== value.toString()) plr.subtitlesBtn.click(); }, - volume(value) { + volume: (value) => { const num = +value; const isMuted = plr.muteBtn.dataset.titleNoTooltip !== 'Mute'; if (num === 0) { @@ -63,7 +57,7 @@ export const valueSetters: ValueSetters & ValueSetterHelpers = { } } }, - quality(value) { - this._ytSettingItem(QUALITY, value); - }, + quality: setYT(QUALITY), +} satisfies { + [P in config.Setting]: (value: Required[P]) => void; };