Skip to content

Commit

Permalink
Merge pull request #45 from Fabrizz/dev-features
Browse files Browse the repository at this point in the history
Added fix for edge case (freeze -> unsync)
  • Loading branch information
Fabrizz authored Jan 15, 2024
2 parents e1a5ad6 + 709c4e5 commit 87a8243
Showing 1 changed file with 106 additions and 95 deletions.
201 changes: 106 additions & 95 deletions utils/SpotifyDomBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1093,106 +1093,117 @@ class SpotifyDomBuilder {

/* TEXT DYNAMIC SCROLL */
setScrollAnimation(disable, newSong, ts) {
if (!disable && !newSong) {
if (Number(ts) > 8000) {
if (!this.scrollerStatus) {
this.scrollerStatus = true;
const container = document.getElementById(
"VSNO-TARGET-TEXTCONTAINER",
);
const subtitle = document.getElementById(
"VSNO-TARGET-SUBTITLE",
).offsetWidth;
const title =
document.getElementById("VSNO-TARGET-TITLE").offsetWidth;

const containerWidth = container.offsetWidth;
const titleData = [
title,
title - containerWidth,
5000 + (title - containerWidth) * 6,
];
const subtitleData = [
subtitle,
subtitle - containerWidth,
5000 + (subtitle - containerWidth) * 6,
];

if (titleData[1] > 0 && subtitleData[1] > 0) {
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-SIZE-TITLE",
`${titleData[1]}px`,
);
document
.getElementById("VSNO-TARGET-TITLE")
.classList.add("scroll");
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-SIZE-SUBTITLE",
`${subtitleData[1]}px`,
);
document
.getElementById("VSNO-TARGET-SUBTITLE")
.classList.add("scroll");
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-TIMING-SUM-TITLE",
`${titleData[2]}ms`,
);
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-TIMING-SUM-SUBTITLE",
`${subtitleData[2]}ms`,
);
} else if (titleData[1] > 0) {
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-SIZE-TITLE",
`${titleData[1]}px`,
);
document
.getElementById("VSNO-TARGET-TITLE")
.classList.add("scroll");
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-TIMING-SUM-TITLE",
`${titleData[2]}ms`,
);
} else if (subtitleData[1] > 0) {
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-SIZE-SUBTITLE",
`${subtitleData[1]}px`,
);
document
.getElementById("VSNO-TARGET-SUBTITLE")
.classList.add("scroll");
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-TIMING-SUM-SUBTITLE",
`${subtitleData[2]}ms`,
try {
if (!disable && !newSong) {
if (Number(ts) > 8000) {
if (!this.scrollerStatus) {
this.scrollerStatus = true;
const container = document.getElementById(
"VSNO-TARGET-TEXTCONTAINER",
);
const subtitle = document.getElementById(
"VSNO-TARGET-SUBTITLE",
).offsetWidth;
const title =
document.getElementById("VSNO-TARGET-TITLE").offsetWidth;

const containerWidth = container.offsetWidth;
const titleData = [
title,
title - containerWidth,
5000 + (title - containerWidth) * 6,
];
const subtitleData = [
subtitle,
subtitle - containerWidth,
5000 + (subtitle - containerWidth) * 6,
];

if (titleData[1] > 0 && subtitleData[1] > 0) {
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-SIZE-TITLE",
`${titleData[1]}px`,
);
document
.getElementById("VSNO-TARGET-TITLE")
.classList.add("scroll");
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-SIZE-SUBTITLE",
`${subtitleData[1]}px`,
);
document
.getElementById("VSNO-TARGET-SUBTITLE")
.classList.add("scroll");
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-TIMING-SUM-TITLE",
`${titleData[2]}ms`,
);
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-TIMING-SUM-SUBTITLE",
`${subtitleData[2]}ms`,
);
} else if (titleData[1] > 0) {
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-SIZE-TITLE",
`${titleData[1]}px`,
);
document
.getElementById("VSNO-TARGET-TITLE")
.classList.add("scroll");
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-TIMING-SUM-TITLE",
`${titleData[2]}ms`,
);
} else if (subtitleData[1] > 0) {
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-SIZE-SUBTITLE",
`${subtitleData[1]}px`,
);
document
.getElementById("VSNO-TARGET-SUBTITLE")
.classList.add("scroll");
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-TIMING-SUM-SUBTITLE",
`${subtitleData[2]}ms`,
);
}
}
}
} else {
if (this.scrollerStatus) {
this.scrollerStatus = false;
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-SIZE-TITLE",
"0px",
);
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-SIZE-SUBTITLE",
"0px",
);
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-TIMING-SUM-TITLE",
"0ms",
);
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-TIMING-SUM-SUBTITLE",
"0ms",
);
document
.getElementById("VSNO-TARGET-SUBTITLE")
.classList.remove("scroll");
document.getElementById("VSNO-TARGET-TITLE").classList.remove("scroll");
}
}
} else {
if (this.scrollerStatus) {
this.scrollerStatus = false;
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-SIZE-TITLE",
"0px",
);
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-SIZE-SUBTITLE",
"0px",
);
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-TIMING-SUM-TITLE",
"0ms",
);
this.root.style.setProperty(
"--ONSP-INTERNAL-SCROLLER-TIMING-SUM-SUBTITLE",
"0ms",
);
document
.getElementById("VSNO-TARGET-SUBTITLE")
.classList.remove("scroll");
document.getElementById("VSNO-TARGET-TITLE").classList.remove("scroll");
}
} catch (error) {
console.info(
`%c· MMM-OnSpotify %c %c[INFO]%c Unknown unsync, could not change scroller status`,
"background-color:#84CC16;color:black;border-radius:0.4em",
"",
"background-color:orange;color:black",
"",
);
}

}

/* Utils */
Expand Down

0 comments on commit 87a8243

Please sign in to comment.