Skip to content
This repository was archived by the owner on Aug 20, 2024. It is now read-only.

Commit 6d88d02

Browse files
committed
Fix label text and catch exception getting colors
1 parent 0ba3f1f commit 6d88d02

3 files changed

Lines changed: 25 additions & 15 deletions

File tree

dist/spicetify-playlist-labels.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ export async function getPlaylistItems(uri) {
99

1010
export async function getPlaylistColor(imageUri) {
1111
const { fetchExtractedColors } = Spicetify.GraphQL.Definitions;
12-
const data = await Spicetify.GraphQL.Request(
13-
fetchExtractedColors,
14-
{ uris: [imageUri] },
15-
);
16-
return data.data?.extractedColors?.[0];
12+
try {
13+
const data = await Spicetify.GraphQL.Request(
14+
fetchExtractedColors,
15+
{ uris: [imageUri] },
16+
);
17+
return data.data?.extractedColors?.[0];
18+
} catch (error) {
19+
return null;
20+
}
1721
}
1822

1923
export async function removeTrackFromPlaylist(playlistUri, trackUri) {

src/app.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,26 @@ function updateTracklist() {
9393
labelColumn = document.createElement("div");
9494
const dummyImgSrc = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
9595

96-
function getFirstCharacters(inputString) {
96+
function isHalfWidth(char) {
97+
// Check if the character is half-width based on its Unicode code point
98+
return (char.codePointAt(0) <= 255 || (char.codePointAt(0) >= 65281 && char.codePointAt(0) <= 65374));
99+
}
100+
101+
function getFirstCharacters(inputString) {
97102
// Split the input string into words
98103
const words = inputString.split(' ');
99-
104+
100105
// Extract the first two words
101106
const firstWord = words[0];
102107
const secondWord = words.length > 1 ? words[1] : '';
103-
104-
// Get either one emoji or the first two letters
105-
const firstCharacters = Array.from(firstWord).slice(0, 1).join('') +
106-
(secondWord ? Array.from(secondWord).slice(0, 1).join('') : '');
107-
108-
return firstCharacters;
109-
}
108+
const firstCharacter = Array.from(firstWord).slice(0, 1).join('');
109+
const secondCharacter = secondWord ? Array.from(secondWord).slice(0, 1).join('') : '';
110+
111+
// Check if the first character of the first word is half-width
112+
const isFirstCharacterHalfWidth = isHalfWidth(firstWord.charAt(0));
113+
114+
return firstCharacter + (isFirstCharacterHalfWidth ? secondCharacter : '');
115+
}
110116

111117
ReactDOM.render(
112118
<div className="spicetify-playlist-labels-labels-container">

0 commit comments

Comments
 (0)