2021-07-04 06:40:40 +02:00
|
|
|
window.addEventListener("load", rotateTurntable = () => {
|
2021-10-23 19:28:57 +02:00
|
|
|
const SpicetifyOrigin = Spicetify.Player.origin;
|
2021-07-04 16:45:09 +02:00
|
|
|
const fadBtn = document.querySelector(".main-topBar-button[title='Full App Display']");
|
|
|
|
|
2021-10-23 19:28:57 +02:00
|
|
|
if (!SpicetifyOrigin?._state || !fadBtn) {
|
2021-07-04 06:40:40 +02:00
|
|
|
setTimeout(rotateTurntable, 250);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-06 17:36:30 +02:00
|
|
|
const adModalStyle = document.createElement("style");
|
2021-07-09 19:50:23 +02:00
|
|
|
const STYLE_FOR_AD_MODAL = `
|
2021-07-06 17:36:30 +02:00
|
|
|
.ReactModalPortal {
|
|
|
|
display: none
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
adModalStyle.innerHTML = STYLE_FOR_AD_MODAL;
|
|
|
|
|
2021-10-23 19:28:57 +02:00
|
|
|
const fadHeartContainer = document.createElement("div");
|
|
|
|
const fadHeart = document.createElement("button");
|
|
|
|
const fadHeartSvg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
|
|
fadHeartContainer.classList.add("fad-heart-container");
|
|
|
|
fadHeart.classList.add("fad-heart");
|
|
|
|
fadHeartSvg.setAttribute("width", "16");
|
|
|
|
fadHeartSvg.setAttribute("height", "16");
|
|
|
|
fadHeartSvg.setAttribute("viewBox", "0 0 16 16");
|
|
|
|
fadHeart.appendChild(fadHeartSvg);
|
|
|
|
fadHeartContainer.appendChild(fadHeart);
|
|
|
|
|
|
|
|
const songPreviewContainer = document.createElement("div");
|
|
|
|
const previousSong = document.createElement("button");
|
|
|
|
const nextSong = document.createElement("button");
|
|
|
|
songPreviewContainer.classList.add("song-preview");
|
|
|
|
songPreviewContainer.append(previousSong, nextSong);
|
|
|
|
|
|
|
|
let isPlaying, clickedFadBtn;
|
|
|
|
|
|
|
|
function handleRotate(eventType) {
|
2021-10-25 18:12:13 +02:00
|
|
|
const coverArt = document.querySelector(".cover-art-image");
|
2021-07-04 06:40:40 +02:00
|
|
|
const fadArt = document.querySelector("#fad-art-image");
|
2021-05-23 23:19:59 +02:00
|
|
|
|
2021-10-23 19:28:57 +02:00
|
|
|
if (
|
|
|
|
eventType == "load" && !SpicetifyOrigin._state.isPaused
|
|
|
|
||
|
|
|
|
eventType == "playpause" && !isPlaying
|
|
|
|
||
|
|
|
|
!eventType && isPlaying
|
|
|
|
) {
|
2021-10-25 18:12:13 +02:00
|
|
|
coverArt.style.setProperty("animation-play-state", "running");
|
2021-10-23 19:28:57 +02:00
|
|
|
fadArt?.style.setProperty("animation-play-state", "running");
|
|
|
|
if (eventType) isPlaying = true;
|
2021-07-04 06:40:40 +02:00
|
|
|
} else {
|
2021-10-25 18:12:13 +02:00
|
|
|
coverArt.style.setProperty("animation-play-state", "paused");
|
2021-10-23 19:28:57 +02:00
|
|
|
fadArt?.style.setProperty("animation-play-state", "paused");
|
|
|
|
if (eventType) isPlaying = false;
|
2021-05-23 23:19:59 +02:00
|
|
|
}
|
2021-07-04 06:40:40 +02:00
|
|
|
}
|
2021-05-23 23:19:59 +02:00
|
|
|
|
2021-10-23 19:28:57 +02:00
|
|
|
function handleFadBtn(event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleFadControl() {
|
2021-07-04 07:06:54 +02:00
|
|
|
const fadControlsBtns = document.querySelectorAll("#fad-controls button");
|
|
|
|
|
|
|
|
for (const fadControl of fadControlsBtns) {
|
2021-10-23 19:28:57 +02:00
|
|
|
fadControl.addEventListener("dblclick", handleFadBtn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleFadHeart(fromEvent) {
|
|
|
|
const isFadHeartContainer = document.querySelector(".fad-heart-container");
|
|
|
|
|
|
|
|
const stateItem = SpicetifyOrigin._state.item;
|
|
|
|
|
|
|
|
if (stateItem.isLocal || stateItem.type == "ad") {
|
|
|
|
isFadHeartContainer?.remove();
|
|
|
|
return;
|
2021-07-04 07:06:54 +02:00
|
|
|
}
|
2021-10-23 19:28:57 +02:00
|
|
|
|
|
|
|
const fadFg = document.querySelector("#fad-foreground");
|
|
|
|
|
|
|
|
const fadHeartState = Spicetify.Player.getHeart();
|
|
|
|
|
|
|
|
if (!fromEvent && fadFg && !isFadHeartContainer) fadFg.appendChild(fadHeartContainer);
|
|
|
|
|
|
|
|
if (!fromEvent && fadHeartState || fromEvent && !fadHeartState) {
|
|
|
|
fadHeartSvg.innerHTML = Spicetify.SVGIcons["heart-active"];
|
|
|
|
fadHeart.classList.add("checked");
|
|
|
|
} else {
|
|
|
|
fadHeartSvg.innerHTML = Spicetify.SVGIcons.heart;
|
|
|
|
fadHeart.classList.remove("checked");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fromEvent) Spicetify.Player.toggleHeart();
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleTracksNamePreview() {
|
|
|
|
const prevTracks = Spicetify.Queue.prevTracks;
|
2021-10-25 18:37:19 +02:00
|
|
|
const currentTrack = Spicetify.Queue.track;
|
2021-10-23 19:28:57 +02:00
|
|
|
const nextTracks = Spicetify.Queue.nextTracks;
|
|
|
|
|
|
|
|
trackCondition = element => !element.contextTrack.metadata.hidden && element.provider != "ad";
|
|
|
|
|
|
|
|
const prevTrack = prevTracks.slice().reverse().find(trackCondition);
|
|
|
|
const nextTrack = nextTracks.find(trackCondition);
|
2021-10-25 18:37:19 +02:00
|
|
|
|
|
|
|
const prevTrackTitle = prevTrack.contextTrack.metadata.title;
|
|
|
|
const currentTrackTitle = currentTrack.contextTrack.metadata.title;
|
|
|
|
const nextTrackTitle = nextTrack.contextTrack.metadata.title;
|
|
|
|
|
|
|
|
if (currentTrackTitle === prevTrackTitle && currentTrackTitle === nextTrackTitle) {
|
|
|
|
previousSong.innerHTML = "";
|
|
|
|
nextSong.innerHTML = "";
|
|
|
|
} else {
|
|
|
|
previousSong.innerHTML = `< ${prevTrackTitle}`;
|
|
|
|
nextSong.innerHTML = `${nextTrackTitle} >`;
|
|
|
|
}
|
2021-07-04 07:06:54 +02:00
|
|
|
}
|
|
|
|
|
2021-07-04 16:45:09 +02:00
|
|
|
function handleConfigSwitch() {
|
2021-10-23 19:28:57 +02:00
|
|
|
const fullAppDisplay = document.querySelector("#full-app-display");
|
|
|
|
const fadFg = document.querySelector("#fad-foreground");
|
|
|
|
const genericModal = document.querySelector("generic-modal");
|
|
|
|
|
|
|
|
const stateItem = SpicetifyOrigin._state.item;
|
|
|
|
|
|
|
|
if (!stateItem.isLocal && stateItem.type != "ad") fadFg.appendChild(fadHeartContainer);
|
|
|
|
fullAppDisplay.appendChild(songPreviewContainer);
|
|
|
|
|
|
|
|
genericModal.remove();
|
2021-07-04 07:06:54 +02:00
|
|
|
|
|
|
|
handleRotate();
|
2021-10-23 19:28:57 +02:00
|
|
|
handleFadControl();
|
2021-07-04 07:06:54 +02:00
|
|
|
}
|
|
|
|
|
2021-07-09 19:50:23 +02:00
|
|
|
function handleBackdrop(fullAppDisplay, setBlurBackdropBtn) {
|
2021-07-07 18:40:08 +02:00
|
|
|
if (!+localStorage.getItem("enableBlurFad")) {
|
2021-10-23 19:28:57 +02:00
|
|
|
fullAppDisplay.dataset.isBlurFad = "true";
|
2021-07-09 19:50:23 +02:00
|
|
|
setBlurBackdropBtn.classList.remove("disabled");
|
2021-07-07 18:40:08 +02:00
|
|
|
|
|
|
|
localStorage.setItem("enableBlurFad", "1");
|
|
|
|
} else {
|
2021-10-23 19:28:57 +02:00
|
|
|
fullAppDisplay.dataset.isBlurFad = "false";
|
2021-07-09 19:50:23 +02:00
|
|
|
setBlurBackdropBtn.classList.add("disabled");
|
2021-07-07 18:40:08 +02:00
|
|
|
|
|
|
|
localStorage.setItem("enableBlurFad", "0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-09 19:50:23 +02:00
|
|
|
function handleContextMenu(fullAppDisplay) {
|
2021-07-07 18:40:08 +02:00
|
|
|
const configContainer = document.querySelector("#popup-config-container");
|
|
|
|
const settingRowReferenceNode = document.querySelectorAll("#popup-config-container > div")[0];
|
|
|
|
|
|
|
|
const settingRowContainer = document.createElement("div");
|
2021-07-09 19:50:23 +02:00
|
|
|
const settingRow = `
|
2021-07-07 18:40:08 +02:00
|
|
|
<div class="setting-row">
|
|
|
|
<label class="col description">Enable blur backdrop</label>
|
|
|
|
<div class="col action">
|
2021-07-09 19:50:23 +02:00
|
|
|
<button class="${+localStorage.getItem("enableBlurFad") ? "switch" : "switch disabled"}" data-blur-fad>
|
2021-07-07 18:40:08 +02:00
|
|
|
<svg height="16" width="16" viewBox="0 0 16 16" fill="currentColor">
|
|
|
|
<path d="M13.985 2.383L5.127 12.754 1.388 8.375l-.658.77 4.397 5.149 9.618-11.262z"></path>
|
|
|
|
</svg>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
settingRowContainer.innerHTML = settingRow;
|
|
|
|
configContainer.insertBefore(settingRowContainer, settingRowReferenceNode);
|
2021-10-23 19:28:57 +02:00
|
|
|
|
2021-07-04 06:40:40 +02:00
|
|
|
const configSwitchBtns = document.querySelectorAll("#popup-config-container button.switch");
|
2021-07-09 19:50:23 +02:00
|
|
|
const setBlurBackdropBtn = document.querySelector("[data-blur-fad]");
|
2021-07-07 18:40:08 +02:00
|
|
|
|
2021-07-04 06:40:40 +02:00
|
|
|
for (const configSwitch of configSwitchBtns) {
|
2021-07-04 16:45:09 +02:00
|
|
|
configSwitch.addEventListener("click", handleConfigSwitch);
|
2021-07-04 06:40:40 +02:00
|
|
|
}
|
2021-07-07 18:40:08 +02:00
|
|
|
|
2021-07-09 19:50:23 +02:00
|
|
|
setBlurBackdropBtn.addEventListener("click", () => handleBackdrop(fullAppDisplay, setBlurBackdropBtn));
|
2021-07-04 16:45:09 +02:00
|
|
|
}
|
|
|
|
|
2021-10-23 19:28:57 +02:00
|
|
|
function handleMainInterface(fromActive, topbarContentFadeIn) {
|
2021-07-06 16:42:25 +02:00
|
|
|
const mainInterface = document.querySelector("#main");
|
|
|
|
const mainPlayBtn = document.querySelector(".main-playButton-PlayButton");
|
|
|
|
const mainTopbarTitle = document.querySelector(".main-entityHeader-topbarTitle");
|
2021-07-06 17:36:30 +02:00
|
|
|
const billboard = document.querySelector("#view-billboard-ad");
|
2021-07-06 16:42:25 +02:00
|
|
|
|
2021-10-23 19:28:57 +02:00
|
|
|
if (fromActive) {
|
|
|
|
if (!topbarContentFadeIn) {
|
|
|
|
mainPlayBtn?.style.setProperty("opacity", "0", "important");
|
|
|
|
mainTopbarTitle?.style.setProperty("opacity", "0", "important");
|
|
|
|
}
|
2021-07-06 16:42:25 +02:00
|
|
|
|
2021-10-23 19:28:57 +02:00
|
|
|
mainInterface.style.display = "none";
|
|
|
|
document.body.append(adModalStyle);
|
|
|
|
} else {
|
|
|
|
mainInterface.style.display = "block";
|
|
|
|
billboard?.closest(".ReactModalPortal").remove();
|
|
|
|
adModalStyle.remove();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
mainPlayBtn?.style.removeProperty("opacity");
|
|
|
|
mainTopbarTitle?.style.removeProperty("opacity");
|
|
|
|
}, 250);
|
|
|
|
}
|
2021-07-06 16:42:25 +02:00
|
|
|
}
|
|
|
|
|
2021-10-23 19:28:57 +02:00
|
|
|
handleRotate("load");
|
|
|
|
|
|
|
|
Spicetify.Player.addEventListener("onplaypause", () => handleRotate("playpause"));
|
|
|
|
Spicetify.Player.addEventListener("songchange", () => {
|
|
|
|
setTimeout(() => {
|
2021-10-25 18:12:13 +02:00
|
|
|
handleRotate();
|
2021-10-23 19:28:57 +02:00
|
|
|
handleFadHeart();
|
|
|
|
handleTracksNamePreview();
|
|
|
|
}, 500);
|
|
|
|
});
|
2021-07-04 16:45:09 +02:00
|
|
|
|
2021-10-23 19:28:57 +02:00
|
|
|
fadHeart.addEventListener("click", () => handleFadHeart(true));
|
|
|
|
previousSong.addEventListener("click", () => SpicetifyOrigin.skipToPrevious());
|
|
|
|
nextSong.addEventListener("click", () => SpicetifyOrigin.skipToNext());
|
|
|
|
|
|
|
|
fadHeart.addEventListener("dblclick", handleFadBtn);
|
|
|
|
previousSong.addEventListener("dblclick", handleFadBtn);
|
|
|
|
nextSong.addEventListener("dblclick", handleFadBtn);
|
2021-07-04 16:45:09 +02:00
|
|
|
|
|
|
|
fadBtn.addEventListener("click", () => {
|
2021-07-06 16:42:25 +02:00
|
|
|
const topbarContentFadeIn = document.querySelector(".main-entityHeader-topbarContentFadeIn");
|
2021-07-04 16:45:09 +02:00
|
|
|
const fullAppDisplay = document.querySelector("#full-app-display");
|
2021-07-07 18:40:08 +02:00
|
|
|
|
2021-07-09 19:50:23 +02:00
|
|
|
if (!clickedFadBtn) {
|
2021-10-23 19:28:57 +02:00
|
|
|
if (+localStorage.getItem("enableBlurFad")) fullAppDisplay.dataset.isBlurFad = "true";
|
|
|
|
fullAppDisplay.appendChild(songPreviewContainer);
|
2021-07-09 19:50:23 +02:00
|
|
|
|
2021-10-23 19:28:57 +02:00
|
|
|
// if (!songPreviewContainer.textContent.length) handleTracksNamePreview();
|
|
|
|
handleFadControl();
|
2021-07-04 16:45:09 +02:00
|
|
|
|
2021-10-23 19:28:57 +02:00
|
|
|
fullAppDisplay.addEventListener("contextmenu", () => handleContextMenu(fullAppDisplay), { once: true });
|
2021-07-04 16:45:09 +02:00
|
|
|
|
2021-10-23 19:28:57 +02:00
|
|
|
fullAppDisplay.addEventListener("dblclick", () => handleMainInterface());
|
2021-07-04 16:45:09 +02:00
|
|
|
|
2021-10-23 19:28:57 +02:00
|
|
|
clickedFadBtn = true;
|
2021-07-06 16:42:25 +02:00
|
|
|
}
|
|
|
|
|
2021-10-23 19:28:57 +02:00
|
|
|
handleMainInterface("active", topbarContentFadeIn);
|
|
|
|
handleFadHeart();
|
|
|
|
handleTracksNamePreview();
|
|
|
|
handleRotate();
|
2021-07-04 06:40:40 +02:00
|
|
|
});
|
2021-05-23 23:19:59 +02:00
|
|
|
});
|