Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Lseoksee committed Feb 11, 2025
1 parent 047a997 commit 2167650
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
33 changes: 24 additions & 9 deletions CustomApps/lyrics-plus/Pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ const SyncedLyricsPage = react.memo(({ lyrics = [], provider, copyright, isKara
// If we have original text and we are showing translated below, we should show the original text
// Otherwise we should show the translated text
const lineText = originalText && showTranslatedBelow ? originalText : text;
const belowMode = showTranslatedBelow && originalText && originalText !== text;

// Convert lyrics to text for comparison
const belowOrigin = typeof originalText === "object" ? originalText?.props?.children?.[0] : originalText;
const belowTxt = typeof text === "object" ? text?.props?.children?.[0] : text;

const belowMode = showTranslatedBelow && originalText && belowOrigin !== belowTxt;

return react.createElement(
"div",
Expand Down Expand Up @@ -214,8 +219,8 @@ const SyncedLyricsPage = react.memo(({ lyrics = [], provider, copyright, isKara
onContextMenu: (event) => {
event.preventDefault();
Spicetify.Platform.ClipboardAPI.copy(Utils.convertParsedToLRC(lyrics, belowMode).conver)
.then(() => Spicetify.showNotification("Lyrics copied to clipboard"))
.catch(() => Spicetify.showNotification("Failed to copy lyrics to clipboard"));
.then(() => Spicetify.showNotification("Translated lyrics copied to clipboard"))
.catch(() => Spicetify.showNotification("Failed to copy translated lyrics to clipboard"));
},
},
text
Expand Down Expand Up @@ -448,7 +453,12 @@ const SyncedExpandedLyricsPage = react.memo(({ lyrics, provider, copyright, isKa
// If we have original text and we are showing translated below, we should show the original text
// Otherwise we should show the translated text
const lineText = originalText && showTranslatedBelow ? originalText : text;
const belowMode = showTranslatedBelow && originalText && originalText !== text;

// Convert lyrics to text for comparison
const belowOrigin = typeof originalText === "object" ? originalText?.props?.children?.[0] : originalText;
const belowTxt = typeof text === "object" ? text?.props?.children?.[0] : text;

const belowMode = showTranslatedBelow && originalText && belowOrigin !== belowTxt;

return react.createElement(
"div",
Expand Down Expand Up @@ -486,8 +496,8 @@ const SyncedExpandedLyricsPage = react.memo(({ lyrics, provider, copyright, isKa
onContextMenu: (event) => {
event.preventDefault();
Spicetify.Platform.ClipboardAPI.copy(Utils.convertParsedToLRC(lyrics, belowMode).conver)
.then(() => Spicetify.showNotification("Lyrics copied to clipboard"))
.catch(() => Spicetify.showNotification("Failed to copy lyrics to clipboard"));
.then(() => Spicetify.showNotification("Translated lyrics copied to clipboard"))
.catch(() => Spicetify.showNotification("Failed to copy translated lyrics to clipboard"));
},
},
text
Expand Down Expand Up @@ -519,7 +529,12 @@ const UnsyncedLyricsPage = react.memo(({ lyrics, provider, copyright }) => {
// If we have original text and we are showing translated below, we should show the original text
// Otherwise we should show the translated text
const lineText = originalText && showTranslatedBelow ? originalText : text;
const belowMode = showTranslatedBelow && originalText && originalText !== text;

// Convert lyrics to text for comparison
const belowOrigin = typeof originalText === "object" ? originalText?.props?.children?.[0] : originalText;
const belowTxt = typeof text === "object" ? text?.props?.children?.[0] : text;

const belowMode = showTranslatedBelow && originalText && belowOrigin !== belowTxt;

return react.createElement(
"div",
Expand Down Expand Up @@ -548,8 +563,8 @@ const UnsyncedLyricsPage = react.memo(({ lyrics, provider, copyright }) => {
onContextMenu: (event) => {
event.preventDefault();
Spicetify.Platform.ClipboardAPI.copy(Utils.convertParsedToUnsynced(lyrics, belowMode).conver)
.then(() => Spicetify.showNotification("Lyrics copied to clipboard"))
.catch(() => Spicetify.showNotification("Failed to copy lyrics to clipboard"));
.then(() => Spicetify.showNotification("Translated lyrics copied to clipboard"))
.catch(() => Spicetify.showNotification("Failed to copy translated lyrics to clipboard"));
},
},
text
Expand Down
20 changes: 11 additions & 9 deletions CustomApps/lyrics-plus/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ const Utils = {
const lyric = {
startTime: lyricsToTranslate[i].startTime || 0,
text: this.rubyTextToReact(translatedLines[i]),
originalText: lyricsToTranslate[i].text,
};
state[stateName].push(lyric);
}
},
/** It seems that this function is not being used, but I'll keep it just in case it’s needed in the future.*/
processTranslatedOriginalLyrics(lyrics, synced) {
const data = [];
const dataSouce = {};
Expand Down Expand Up @@ -248,24 +250,24 @@ const Utils = {

if (isBelow) {
for (const line of lyrics) {
if (line.originalText !== "object") {
original += `${line.originalText}\n`;
} else {
if (typeof line.originalText === "object") {
original += `${line.originalText?.props?.children?.[0]}\n`;
} else {
original += `${line.originalText}\n`;
}

if (line.text !== "object") {
conver += `${line.text}\n`;
} else {
if (typeof line.text === "object") {
conver += `${line.text?.props?.children?.[0]}\n`;
} else {
conver += `${line.text}\n`;
}
}
} else {
for (const line of lyrics) {
if (line.text !== "object") {
original += `${line.text}\n`;
} else {
if (typeof line.text === "object") {
original += `${line.text?.props?.children?.[0]}\n`;
} else {
original += `${line.text}\n`;
}
}
}
Expand Down

0 comments on commit 2167650

Please sign in to comment.