Skip to content

Commit

Permalink
lint arrowParentheses asNeeded
Browse files Browse the repository at this point in the history
  • Loading branch information
Araxeus committed Dec 30, 2024
1 parent 41c6257 commit f21e2bf
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 42 deletions.
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
},
"javascript": {
"formatter": {
"quoteStyle": "single"
"quoteStyle": "single",
"arrowParentheses": "asNeeded"
}
},
"formatter": {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion unpacked/background-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?.() ??
Expand Down
6 changes: 3 additions & 3 deletions unpacked/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' &&
Expand All @@ -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);
});
};
Expand All @@ -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
Expand Down
46 changes: 22 additions & 24 deletions unpacked/pageAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -216,7 +214,7 @@ class ytvs {
'ytvs_type',
this.#reversedHudTypes[ytvs.hud],
);
this.#activeInstances.forEach((obj) => obj.showVolume());
this.#activeInstances.forEach(obj => obj.showVolume());
}
}

Expand All @@ -227,36 +225,36 @@ 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(),
);
}
}

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 (
config.hudPosition &&
!this.simpleAreEqual(config.hudPosition, this.hudPosition)
) {
this.#config.hudPosition = config.hudPosition;
this.activeInstances.forEach((obj) => obj.updateHudPosition());
this.activeInstances.forEach(obj => obj.updateHudPosition());
}
}

static #initDone = false;
static init() {
window.addEventListener(
'message',
(e) => {
e => {
if (e.origin !== window.location.origin) return;
if (
e.data.type === 'YoutubeVolumeScroll-config-change' &&
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -642,7 +640,7 @@ class YoutubeVolumeScroll {
[ytvs.hudTypes.custom]: 1500,
};

const setOpacity = (opacity) => {
const setOpacity = opacity => {
if (
ytvs.hudPositionMode &&
opacity === 0 &&
Expand Down Expand Up @@ -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]),
);
}

Expand Down Expand Up @@ -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;
});
};
Expand All @@ -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;
Expand All @@ -741,7 +739,7 @@ class YoutubeVolumeScroll {
setShortsControlsPointerEvents('none');
};

dragTarget.ondrop = (ev) => {
dragTarget.ondrop = ev => {
ev.preventDefault();

const dragTargetRect = dragTarget.getBoundingClientRect();
Expand All @@ -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 = {
Expand Down Expand Up @@ -797,7 +795,7 @@ class YoutubeVolumeScroll {
}

Object.keys(hudPosition).forEach(
(pos) => (draggedElement.style[pos] = hudPosition[pos]),
pos => (draggedElement.style[pos] = hudPosition[pos]),
);

const hudPositionToSend = {};
Expand All @@ -807,7 +805,7 @@ class YoutubeVolumeScroll {
setShortsControlsPointerEvents('auto');
};

dragTarget.ondragover = (ev) => {
dragTarget.ondragover = ev => {
ev.preventDefault();
ev.dataTransfer.dropEffect = 'move';
};
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions unpacked/popup/elements/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions unpacked/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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');
}
Expand All @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit f21e2bf

Please sign in to comment.