Skip to content

Commit

Permalink
Merge branch 'master' into posh2
Browse files Browse the repository at this point in the history
  • Loading branch information
SunsetTechuila authored Dec 5, 2023
2 parents e93a17e + 7e89c05 commit aec5de7
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions jsHelper/spicetifyWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ window.Spicetify = {
},
getMute: () => Spicetify.Player.getVolume() === 0,
toggleMute: () => {
document.querySelector(".volume-bar__icon-button").click();
Spicetify.Player.setMute(!Spicetify.Player.getMute());
},
setMute: b => {
const isMuted = Spicetify.Player.getMute();
if ((b && !isMuted) || (!b && isMuted)) {
Spicetify.Player.toggleMute();
if (b) {
const volume = Spicetify.Player.getVolume();
if (volume > 0) Spicetify.Player._volumeBeforeMute = volume;
Spicetify.Player.setVolume(0);
} else {
Spicetify.Player.setVolume(Spicetify.Player._volumeBeforeMute);
}
},
formatTime: ms => {
Expand All @@ -83,7 +86,7 @@ window.Spicetify = {
seconds -= minutes * 60;
return `${minutes}:${seconds > 9 ? "" : "0"}${String(seconds)}`;
},
getHeart: () => document.querySelector(".control-button-heart")?.ariaChecked === "true",
getHeart: () => Spicetify.Player.origin._state.item.metadata["collection.in_collection"] === "true",
pause: () => {
Spicetify.Player.origin.pause();
},
Expand Down Expand Up @@ -111,8 +114,16 @@ window.Spicetify = {
skipForward: (amount = 15e3) => {
Spicetify.Player.origin.seekForward(amount);
},
setHeart: b => {
const uris = [Spicetify.Player.origin._state.item.uri];
if (b) {
Spicetify.Platform.LibraryAPI.add({ uris });
} else {
Spicetify.Platform.LibraryAPI.remove({ uris });
}
},
toggleHeart: () => {
document.querySelector(".control-button-heart")?.click();
Spicetify.Player.setHeart(!Spicetify.Player.getHeart());
}
},
test: () => {
Expand Down Expand Up @@ -202,7 +213,9 @@ window.Spicetify = {
"toggleRepeat",
"toggleShuffle",
"origin",
"playUri"
"playUri",
"setHeart",
"_volumeBeforeMute"
];

const REACT_COMPONENT = [
Expand Down Expand Up @@ -717,6 +730,21 @@ window.Spicetify = {
Spicetify.removeFromQueue = uri => {
return Spicetify.Player.origin._queue.removeFromQueue(uri);
};

Spicetify.Player._volumeBeforeMute = Spicetify.Player.getVolume() || 0.7;
})();

(function waitForPlaybackAPI() {
if (!Spicetify.Platform?.PlaybackAPI) {
setTimeout(waitForPlaybackAPI, 10);
return;
}

Spicetify.Platform.PlaybackAPI._events.addListener("volume", ({ data: { volume } }) => {
if (volume > 0) {
Spicetify.Player._volumeBeforeMute = volume;
}
});
})();

Spicetify.getAudioData = async uri => {
Expand Down

0 comments on commit aec5de7

Please sign in to comment.