From f21e2bfda322e4f09bd2d0be1b40a9497b0fde09 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Mon, 30 Dec 2024 21:35:49 +0200 Subject: [PATCH] lint arrowParentheses asNeeded --- biome.json | 3 +- package.json | 10 +++---- unpacked/background-script.js | 2 +- unpacked/index.js | 6 ++-- unpacked/pageAccess.js | 46 +++++++++++++++---------------- unpacked/popup/elements/slider.js | 4 +-- unpacked/popup/popup.js | 12 ++++---- 7 files changed, 41 insertions(+), 42 deletions(-) diff --git a/biome.json b/biome.json index fe022ab..f5b0650 100644 --- a/biome.json +++ b/biome.json @@ -13,7 +13,8 @@ }, "javascript": { "formatter": { - "quoteStyle": "single" + "quoteStyle": "single", + "arrowParentheses": "asNeeded" } }, "formatter": { diff --git a/package.json b/package.json index efd1cc8..7590965 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,11 @@ "packageManager": "bun@1.1.22", "scripts": { "check": "bun copy_to_dist && bun check_no_copy && del-cli dist", - "check_no_copy": "(bun biome check && web-ext lint -w --ignore-files \"./popup/vendors/*\") || (del-cli dist && exit 1)", - "lint": "bun biome check --write", - "format": "bun biome format --write", + "check_no_copy": "(biome check && web-ext lint -w --ignore-files \"./popup/vendors/*\") || (del-cli dist && exit 1)", + "lint": "biome check --write", + "format": "biome format --write", "sas": "sass --update unpacked/popup", - "release": "release-it", + "release": "release-it && bun b", "publish": "gh workflow run publish.yml", "b": "bun sas && bun copy_to_dist && bun check_no_copy && bun build:firefox && bun build:chromium && del-cli dist", "build:firefox": "x-var web-ext build --filename=\"youtube-volume-scroll_%npm_package_version%_firefox.xpi\"", @@ -85,7 +85,7 @@ "hooks": { "before:init": "bun check", "after:bump": "bun format", - "after:release": "bun b" + "after:release": "echo Successfully released ${name} v${version} to ${repo.repository}." }, "git": { "requireBranch": "main", diff --git a/unpacked/background-script.js b/unpacked/background-script.js index cf4b9a4..d8d6245 100644 --- a/unpacked/background-script.js +++ b/unpacked/background-script.js @@ -7,7 +7,7 @@ const browserApi = globalThis.browser ?? globalThis.chrome ?? null; const permissions = { origins: ['https://www.youtube.com/*', 'https://music.youtube.com/*'], }; -browserApi.permissions.contains(permissions, (result) => { +browserApi.permissions.contains(permissions, result => { if (!result) { browserApi.browserAction?.openPopup?.() ?? browserApi.action?.openPopup?.() ?? diff --git a/unpacked/index.js b/unpacked/index.js index 22dabd2..b65d8d7 100644 --- a/unpacked/index.js +++ b/unpacked/index.js @@ -74,7 +74,7 @@ function checkOverlay() { function init() { loadPageAccess(); - window.addEventListener('message', (e) => { + window.addEventListener('message', e => { if (e.origin !== window.location.origin) return; if ( e.data.type === 'YoutubeVolumeScroll-volume' && @@ -98,7 +98,7 @@ function loadPageAccess() { pageAccess.src = browserApi.runtime.getURL('pageAccess.js'); pageAccess.onload = function () { this.remove(); - browserApi.storage.sync.get('config', (data) => { + browserApi.storage.sync.get('config', data => { if (data.config) sendConfig(data.config); }); }; @@ -114,7 +114,7 @@ function sendConfig(config) { } function setupIncognito() { - browserApi.storage.sync.get('savedVolume', (data) => { + browserApi.storage.sync.get('savedVolume', data => { if (data?.savedVolume !== undefined) { try { // indicate to pageAccess that we are in incognito diff --git a/unpacked/pageAccess.js b/unpacked/pageAccess.js index cc3847b..95bd49a 100644 --- a/unpacked/pageAccess.js +++ b/unpacked/pageAccess.js @@ -157,21 +157,19 @@ class ytvs { } static getCookie(n) { - return document.cookie - .split('; ') - .find((row) => row.startsWith(`${n}=`)); + return document.cookie.split('; ').find(row => row.startsWith(`${n}=`)); } static #setupMouseObserver() { let changedVolumeWhileRightMouseDown = false; - document.addEventListener('mousedown', (e) => { + document.addEventListener('mousedown', e => { if (e.button === 2) { this.#isRightMouseDown = true; } }); - document.addEventListener('mouseup', (e) => { + document.addEventListener('mouseup', e => { if (e.button === 2) { this.#isRightMouseDown = false; if (changedVolumeWhileRightMouseDown) { @@ -196,7 +194,7 @@ class ytvs { } }); - window.addEventListener('message', (e) => { + window.addEventListener('message', e => { if (e.origin !== window.location.origin) return; if (e.data.type === 'YoutubeVolumeScroll-volume') { if (this.#isRightMouseDown) { @@ -216,7 +214,7 @@ class ytvs { 'ytvs_type', this.#reversedHudTypes[ytvs.hud], ); - this.#activeInstances.forEach((obj) => obj.showVolume()); + this.#activeInstances.forEach(obj => obj.showVolume()); } } @@ -227,7 +225,7 @@ class ytvs { if (config.hudPositionMode !== this.hudPositionMode) { this.#config.hudPositionMode = config.hudPositionMode; if (this.hud === this.hudTypes.custom) { - this.#activeInstances.forEach((obj) => + this.#activeInstances.forEach(obj => obj.updateHudPositionMode(), ); } @@ -235,12 +233,12 @@ class ytvs { if (config.hudSize && config.hudSize !== this.hudSize) { this.#config.hudSize = config.hudSize; - this.#activeInstances.forEach((obj) => obj.updateHudSize()); + this.#activeInstances.forEach(obj => obj.updateHudSize()); } if (config.hudColor && config.hudColor !== this.hudColor) { this.#config.hudColor = config.hudColor; - this.#activeInstances.forEach((obj) => obj.updateHudColor()); + this.#activeInstances.forEach(obj => obj.updateHudColor()); } if ( @@ -248,7 +246,7 @@ class ytvs { !this.simpleAreEqual(config.hudPosition, this.hudPosition) ) { this.#config.hudPosition = config.hudPosition; - this.activeInstances.forEach((obj) => obj.updateHudPosition()); + this.activeInstances.forEach(obj => obj.updateHudPosition()); } } @@ -256,7 +254,7 @@ class ytvs { static init() { window.addEventListener( 'message', - (e) => { + e => { if (e.origin !== window.location.origin) return; if ( e.data.type === 'YoutubeVolumeScroll-config-change' && @@ -427,7 +425,7 @@ class YoutubeVolumeScroll { } setupOnWheel() { - ytvs.$(this.scrollTarget).onwheel = (event) => { + ytvs.$(this.scrollTarget).onwheel = event => { if ( ytvs.activationModifier === ytvs.activationModifiers.shift && !event.shiftKey @@ -642,7 +640,7 @@ class YoutubeVolumeScroll { [ytvs.hudTypes.custom]: 1500, }; - const setOpacity = (opacity) => { + const setOpacity = opacity => { if ( ytvs.hudPositionMode && opacity === 0 && @@ -687,7 +685,7 @@ class YoutubeVolumeScroll { const newHudPosition = ytvs.hudPosition[this.type]; Object.keys(newHudPosition).forEach( - (key) => (volumeHud.style[key] = newHudPosition[key]), + key => (volumeHud.style[key] = newHudPosition[key]), ); } @@ -717,11 +715,11 @@ class YoutubeVolumeScroll { let dragOffsetX; let dragOffsetY; - const setShortsControlsPointerEvents = (value) => { + const setShortsControlsPointerEvents = value => { const shortsControls = [ ytvs.$('.player-controls.ytd-reel-video-renderer'), ]; - shortsControls.forEach((c) => { + shortsControls.forEach(c => { if (c) c.style.pointerEvents = value; }); }; @@ -732,7 +730,7 @@ class YoutubeVolumeScroll { draggedElement.style.opacity = 1; draggedElement.textContent ||= `${Math.round(this.api.getVolume())}%`; - draggedElement.ondragstart = (ev) => { + draggedElement.ondragstart = ev => { const rect = ev.target.getBoundingClientRect(); dragOffsetX = ev.clientX - rect.x; @@ -741,7 +739,7 @@ class YoutubeVolumeScroll { setShortsControlsPointerEvents('none'); }; - dragTarget.ondrop = (ev) => { + dragTarget.ondrop = ev => { ev.preventDefault(); const dragTargetRect = dragTarget.getBoundingClientRect(); @@ -759,8 +757,8 @@ class YoutubeVolumeScroll { const controlsHeight = ytvs.$('.ytp-chrome-bottom')?.clientHeight || 0; - const pxToPercent_width = (x) => (x / dragTargetRect.width) * 100; - const pxToPercent_height = (y) => (y / dragTargetRect.height) * 100; + const pxToPercent_width = x => (x / dragTargetRect.width) * 100; + const pxToPercent_height = y => (y / dragTargetRect.height) * 100; const ogStyle = draggedElement.style; const hudPosition = { @@ -797,7 +795,7 @@ class YoutubeVolumeScroll { } Object.keys(hudPosition).forEach( - (pos) => (draggedElement.style[pos] = hudPosition[pos]), + pos => (draggedElement.style[pos] = hudPosition[pos]), ); const hudPositionToSend = {}; @@ -807,7 +805,7 @@ class YoutubeVolumeScroll { setShortsControlsPointerEvents('auto'); }; - dragTarget.ondragover = (ev) => { + dragTarget.ondragover = ev => { ev.preventDefault(); ev.dataTransfer.dropEffect = 'move'; }; @@ -863,7 +861,7 @@ if (!ytvs.isMusic) { if (ytvs.$('ytd-player.ytd-shorts video')) { YoutubeVolumeScroll.newYoutubeShorts(); } else { - const shortsObserver = new MutationObserver((m) => { + const shortsObserver = new MutationObserver(m => { if (m[0].addedNodes[0].tagName === 'YTD-SHORTS') { shortsObserver.disconnect(); const shortsContainer = m[0].addedNodes[0]; diff --git a/unpacked/popup/elements/slider.js b/unpacked/popup/elements/slider.js index 63a2d2c..03eb4a1 100644 --- a/unpacked/popup/elements/slider.js +++ b/unpacked/popup/elements/slider.js @@ -77,11 +77,11 @@ customElements.define( this.value = input.value; }); - const inc = (n) => + const inc = n => (input.value = parseFloat(input.value) + parseFloat(this.step) * n); - input.addEventListener('wheel', (e) => { + input.addEventListener('wheel', e => { // Event.deltaY < 0 means wheel-up (increase), > 0 means wheel-down (decrease) if (e.deltaY !== 0) inc(e.deltaY < 0 ? 1 : -1); // Event.deltaX < 0 means wheel-left (decrease), > 0 means wheel-right (increase) diff --git a/unpacked/popup/popup.js b/unpacked/popup/popup.js index b4305fd..fb20c47 100644 --- a/unpacked/popup/popup.js +++ b/unpacked/popup/popup.js @@ -60,7 +60,7 @@ function sendConfig(timeout = 0) { }, timeout); } -browserApi.storage.sync.get('config', (data) => { +browserApi.storage.sync.get('config', data => { config = { ...defaultConfig, ...(data?.config || {}) }; if ($('#steps_slider')) init(); else { @@ -85,11 +85,11 @@ function init() { const permissions = { origins: ['https://www.youtube.com/*', 'https://music.youtube.com/*'], }; - browserApi.permissions.contains(permissions, (result) => { + browserApi.permissions.contains(permissions, result => { if (!result) { $('body').classList.add('permissions-mode'); $('#permissions_button').onclick = () => { - browserApi.permissions.request(permissions, (granted) => { + browserApi.permissions.request(permissions, granted => { if (granted) { $('body').classList.remove('permissions-mode'); } @@ -100,12 +100,12 @@ function init() { }); } -const setCustomOptionsEnabled = (b) => +const setCustomOptionsEnabled = b => $('body').classList[b ? 'add' : 'remove']('custom-options-enabled'); function setupHudRadio() { const radios = $$('input[name="hud"]'); - radios.forEach((radio) => { + radios.forEach(radio => { radio.onchange = () => { config.hud = parseInt(radio.value, 10); setCustomOptionsEnabled(config.hud === hudTypes.custom); @@ -118,7 +118,7 @@ function setupHudRadio() { function setupActivationModifierRadio() { const radios = $$('input[name="activation_modifier"]'); - radios.forEach((radio) => { + radios.forEach(radio => { radio.onchange = () => { config.activationModifier = parseInt(radio.value, 10); sendConfig();