Skip to content

Commit b8e0d53

Browse files
committed
chore: improve readability 2
1 parent ffa6168 commit b8e0d53

File tree

6 files changed

+48
-47
lines changed

6 files changed

+48
-47
lines changed

src/plugins/music-together/templates/status.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
<div class="music-together-status-container">
33
<img class="music-together-profile big" alt="Profile Image">
44
<div class="music-together-status-item">
5-
<ytmd-trans key="plugins.music-together.name"></ytmd-trans>
5+
<pear-trans key="plugins.music-together.name"></pear-trans>
66
<span id="music-together-status-label">
7-
<ytmd-trans key="plugins.music-together.menu.status.disconnected"></ytmd-trans>
7+
<pear-trans key="plugins.music-together.menu.status.disconnected"></pear-trans>
88
</span>
99
<marquee id="music-together-permission-label">
10-
<ytmd-trans key="plugins.music-together.menu.permission.playlist" style="color: rgba(255, 255, 255, 0.75)"></ytmd-trans>
10+
<pear-trans key="plugins.music-together.menu.permission.playlist" style="color: rgba(255, 255, 255, 0.75)"></pear-trans>
1111
</marquee>
1212
</div>
1313
</div>
1414
<div class="music-together-divider horizontal" style="margin: 16px 0;"></div>
1515
<div class="music-together-status-item">
16-
<ytmd-trans key="plugins.music-together.menu.connected-users"></ytmd-trans>
16+
<pear-trans key="plugins.music-together.menu.connected-users"></pear-trans>
1717
</div>
1818
<div class="music-together-user-container">
1919
<span class="music-together-empty">
20-
<ytmd-trans key="plugins.music-together.menu.empty-user"></ytmd-trans>
20+
<pear-trans key="plugins.music-together.menu.empty-user"></pear-trans>
2121
</span>
2222
</div>
2323
</div>

src/providers/song-info-front.ts

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { MusicPlayer } from '@/types/music-player';
66
import type {
77
AlbumDetails,
88
PlayerOverlays,
9-
VideoDataChangeValue
9+
VideoDataChangeValue,
1010
} from '@/types/player-api-events';
1111

1212
import type { SongInfo } from './song-info';
@@ -21,7 +21,7 @@ window.ipcRenderer.on(
2121
'peard:update-song-info',
2222
(_, extractedSongInfo: SongInfo) => {
2323
songInfo = extractedSongInfo;
24-
}
24+
},
2525
);
2626

2727
// Used because 'loadeddata' or 'loadedmetadata' weren't firing on song start for some users (https://github.com/pear-devs/pear-music/issues/473)
@@ -61,11 +61,11 @@ export const setupRepeatChangedListener = singleton(() => {
6161
getState: () => GetState;
6262
};
6363
}
64-
).__dataHost.getState().queue.repeatMode
64+
).__dataHost.getState().queue.repeatMode,
6565
);
6666
});
6767
repeatObserver.observe(document.querySelector('#right-controls .repeat')!, {
68-
attributeFilter: ['title']
68+
attributeFilter: ['title'],
6969
});
7070

7171
// Emit the initial value as well; as it's persistent between launches.
@@ -75,10 +75,10 @@ export const setupRepeatChangedListener = singleton(() => {
7575
document
7676
.querySelector<
7777
HTMLElement & {
78-
getState: () => GetState;
79-
}
78+
getState: () => GetState;
79+
}
8080
>('ytmusic-player-bar')
81-
?.getState().queue.repeatMode
81+
?.getState().queue.repeatMode,
8282
);
8383
});
8484

@@ -95,22 +95,22 @@ export const setupLikeChangedListener = singleton(() => {
9595
'peard:like-changed',
9696
mapLikeStatus(
9797
(mutations[0].target as HTMLElement)?.getAttribute?.(
98-
LIKE_STATUS_ATTRIBUTE
99-
)
100-
)
98+
LIKE_STATUS_ATTRIBUTE,
99+
),
100+
),
101101
);
102102
});
103103
const likeButtonRenderer = document.querySelector('#like-button-renderer');
104104
if (likeButtonRenderer) {
105105
likeDislikeObserver.observe(likeButtonRenderer, {
106106
attributes: true,
107-
attributeFilter: [LIKE_STATUS_ATTRIBUTE]
107+
attributeFilter: [LIKE_STATUS_ATTRIBUTE],
108108
});
109109

110110
// Emit the initial value as well; as it's persistent between launches.
111111
window.ipcRenderer.send(
112112
'peard:like-changed',
113-
mapLikeStatus(likeButtonRenderer.getAttribute?.(LIKE_STATUS_ATTRIBUTE))
113+
mapLikeStatus(likeButtonRenderer.getAttribute?.(LIKE_STATUS_ATTRIBUTE)),
114114
);
115115
}
116116
});
@@ -119,14 +119,14 @@ export const setupVolumeChangedListener = singleton((api: MusicPlayer) => {
119119
document.querySelector('video')?.addEventListener('volumechange', () => {
120120
window.ipcRenderer.send('peard:volume-changed', {
121121
state: api.getVolume(),
122-
isMuted: api.isMuted()
122+
isMuted: api.isMuted(),
123123
});
124124
});
125125

126126
// Emit the initial value as well; as it's persistent between launches.
127127
window.ipcRenderer.send('peard:volume-changed', {
128128
state: api.getVolume(),
129-
isMuted: api.isMuted()
129+
isMuted: api.isMuted(),
130130
});
131131
});
132132

@@ -141,15 +141,15 @@ export const setupShuffleChangedListener = singleton(() => {
141141
const observer = new MutationObserver(() => {
142142
window.ipcRenderer.send(
143143
'peard:shuffle-changed',
144-
(playerBar?.attributes.getNamedItem('shuffle-on') ?? null) !== null
144+
(playerBar?.attributes.getNamedItem('shuffle-on') ?? null) !== null,
145145
);
146146
});
147147

148148
observer.observe(playerBar, {
149149
attributes: true,
150150
attributeFilter: ['shuffle-on'],
151151
childList: false,
152-
subtree: false
152+
subtree: false,
153153
});
154154
});
155155

@@ -165,21 +165,21 @@ export const setupFullScreenChangedListener = singleton(() => {
165165
window.ipcRenderer.send(
166166
'peard:fullscreen-changed',
167167
(playerBar?.attributes.getNamedItem('player-fullscreened') ?? null) !==
168-
null
168+
null,
169169
);
170170
});
171171

172172
observer.observe(playerBar, {
173173
attributes: true,
174174
attributeFilter: ['player-fullscreened'],
175175
childList: false,
176-
subtree: false
176+
subtree: false,
177177
});
178178
});
179179

180180
export const setupAutoPlayChangedListener = singleton(() => {
181181
const autoplaySlider = document.querySelector<HTMLInputElement>(
182-
'.autoplay > tp-yt-paper-toggle-button'
182+
'.autoplay > tp-yt-paper-toggle-button',
183183
);
184184

185185
const observer = new MutationObserver(() => {
@@ -189,7 +189,7 @@ export const setupAutoPlayChangedListener = singleton(() => {
189189
observer.observe(autoplaySlider!, {
190190
attributes: true,
191191
childList: false,
192-
subtree: false
192+
subtree: false,
193193
});
194194
});
195195

@@ -233,25 +233,25 @@ export const setupSongInfo = (api: MusicPlayer) => {
233233
) {
234234
window.ipcRenderer.send('peard:play-or-paused', {
235235
isPaused: status === 'pause',
236-
elapsedSeconds: Math.floor(e.target.currentTime)
236+
elapsedSeconds: Math.floor(e.target.currentTime),
237237
});
238238
}
239239
};
240240

241241
const playPausedHandlers = {
242242
playing: (e: Event) => playPausedHandler(e, 'playing'),
243-
pause: (e: Event) => playPausedHandler(e, 'pause')
243+
pause: (e: Event) => playPausedHandler(e, 'pause'),
244244
};
245245

246246
const videoEventDispatcher = async (
247247
name: string,
248-
videoData: VideoDataChangeValue
248+
videoData: VideoDataChangeValue,
249249
// eslint-disable-next-line @typescript-eslint/require-await
250250
) =>
251251
document.dispatchEvent(
252252
new CustomEvent<VideoDataChanged>('videodatachange', {
253-
detail: { name, videoData }
254-
})
253+
detail: { name, videoData },
254+
}),
255255
);
256256

257257
const waitingEvent = new Set<string>();
@@ -311,7 +311,7 @@ export const setupSongInfo = (api: MusicPlayer) => {
311311
title,
312312
author,
313313
video_id: videoId,
314-
list: playlistId
314+
list: playlistId,
315315
} = api.getVideoData();
316316

317317
const watchNextResponse = api.getWatchNextResponse();
@@ -326,7 +326,7 @@ export const setupSongInfo = (api: MusicPlayer) => {
326326
lengthSeconds: video.duration,
327327
loading: true,
328328

329-
ytmdWatchNextResponse: watchNextResponse
329+
['\u0079\u0074\u006d\u0064WatchNextResponse']: watchNextResponse,
330330
} satisfies VideoDataChangeValue);
331331
}
332332
}
@@ -336,18 +336,19 @@ export const setupSongInfo = (api: MusicPlayer) => {
336336

337337
let playerOverlay: PlayerOverlays | undefined;
338338

339-
if (!videoData.ytmdWatchNextResponse) {
339+
if (!videoData['\u0079\u0074\u006d\u0064WatchNextResponse']) {
340340
playerOverlay = (
341341
Object.entries(videoData).find(
342-
([, value]) => value && Object.hasOwn(value, 'playerOverlays')
342+
([, value]) => value && Object.hasOwn(value, 'playerOverlays'),
343343
) as [string, AlbumDetails | undefined]
344344
)?.[1]?.playerOverlays;
345345
} else {
346-
playerOverlay = videoData.ytmdWatchNextResponse?.playerOverlays;
346+
playerOverlay =
347+
videoData['\u0079\u0074\u006d\u0064WatchNextResponse']?.playerOverlays;
347348
}
348349
data.videoDetails.album =
349350
playerOverlay?.playerOverlayRenderer?.browserMediaSession?.browserMediaSessionRenderer?.album?.runs?.at(
350-
0
351+
0,
351352
)?.text;
352353
data.videoDetails.elapsedSeconds = 0;
353354
data.videoDetails.isPaused = false;

src/renderer.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,12 @@ async function onApiLoaded() {
411411
/**
412412
* Original still using ES5, so we need to define custom elements using ES5 style
413413
*/
414-
const defineYTMDTransElements = () => {
415-
const YTMDTrans = function () {};
414+
const definePearTransElements = () => {
415+
const PearTrans = function () {};
416416
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
417-
YTMDTrans.prototype = Object.create(HTMLElement.prototype);
417+
PearTrans.prototype = Object.create(HTMLElement.prototype);
418418
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
419-
YTMDTrans.prototype.connectedCallback = function () {
419+
PearTrans.prototype.connectedCallback = function () {
420420
const that = this as HTMLElement;
421421
const key = that.getAttribute('key');
422422
if (key) {
@@ -427,8 +427,8 @@ const defineYTMDTransElements = () => {
427427
}
428428
};
429429
customElements.define(
430-
'ytmd-trans',
431-
YTMDTrans as unknown as CustomElementConstructor,
430+
'pear-trans',
431+
PearTrans as unknown as CustomElementConstructor,
432432
);
433433
};
434434

@@ -438,7 +438,7 @@ const preload = async () => {
438438
window.i18n = {
439439
t: i18t.bind(i18next),
440440
};
441-
defineYTMDTransElements();
441+
definePearTransElements();
442442
if (document.body?.dataset?.os) {
443443
document.body.dataset.os = navigator.userAgent;
444444
}

src/types/player-api-events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export type VideoDataChangeValue = Record<string, unknown> & {
258258
/**
259259
* Internal variable (for album data)
260260
**/
261-
ytmdWatchNextResponse?: WatchNextResponse;
261+
['\u0079\u0074\u006d\u0064WatchNextResponse']?: WatchNextResponse;
262262
};
263263

264264
export interface PlayerAPIEvents {

src/utils/custom-element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import { customElement, type ComponentType } from 'solid-element';
33
export const anonymousCustomElement = <T extends object>(
44
ComponentType: ComponentType<T>,
55
): CustomElementConstructor =>
6-
customElement(`ytmd-${crypto.randomUUID()}`, ComponentType);
6+
customElement(`pear-${crypto.randomUUID()}`, ComponentType);

src/yt-web-components.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ declare module 'solid-js' {
3535
icon: Icons;
3636
}
3737

38-
interface YtmdTransProps {
38+
interface PearTransProps {
3939
key?: string;
4040
}
4141

4242
interface IntrinsicElements extends MDUIElements {
4343
'center': ComponentProps<'div'>;
44-
'ytmd-trans': ComponentProps<'span'> & YtmdTransProps;
44+
'pear-trans': ComponentProps<'span'> & PearTransProps;
4545
'yt-formatted-string': ComponentProps<'span'> & YtFormattedStringProps;
4646
'yt-button-renderer': ComponentProps<'button'> & YtButtonRendererProps;
4747
'yt-touch-feedback-shape': ComponentProps<'div'>;

0 commit comments

Comments
 (0)