Skip to content

Commit 923669e

Browse files
committed
feat(wrapper): add smooth scrolling for Spotify 1.2.56
1 parent 741bcc1 commit 923669e

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

jsHelper/spicetifyWrapper.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,51 @@ window.Spicetify = {
306306
Platform: {},
307307
};
308308

309+
// Based on https://blog.aziz.tn/2025/01/spotify-fix-lagging-issue-on-scrolling.html
310+
function applyScrollingFix() {
311+
const scrollableElements = Array.from(document.querySelectorAll("*")).filter((el) => {
312+
if (
313+
el.id === "context-menu" ||
314+
el.closest("#context-menu") ||
315+
el.getAttribute("role") === "dialog" ||
316+
el.classList.contains("popup") ||
317+
el.getAttribute("aria-haspopup") === "true"
318+
)
319+
return false;
320+
321+
const style = window.getComputedStyle(el);
322+
return style.overflow === "auto" || style.overflow === "scroll" || style.overflowY === "auto" || style.overflowY === "scroll";
323+
});
324+
325+
for (const el of scrollableElements) {
326+
if (!el.hasAttribute("data-scroll-optimized")) {
327+
el.style.willChange = "transform";
328+
el.style.transform = "translate3d(0, 0, 0)";
329+
el.setAttribute("data-scroll-optimized", "true");
330+
}
331+
}
332+
}
333+
334+
const observer = new MutationObserver(applyScrollingFix);
335+
336+
observer.observe(document.body, {
337+
childList: true,
338+
subtree: true,
339+
attributes: false,
340+
});
341+
342+
const originalPushState = history.pushState;
343+
history.pushState = function (...args) {
344+
originalPushState.apply(this, args);
345+
setTimeout(applyScrollingFix, 100);
346+
};
347+
348+
window.addEventListener("popstate", () => {
349+
setTimeout(applyScrollingFix, 100);
350+
});
351+
352+
applyScrollingFix();
353+
309354
(function waitForPlatform() {
310355
if (!Spicetify._platform) {
311356
setTimeout(waitForPlatform, 50);

0 commit comments

Comments
 (0)