Skip to content

Instantly share code, notes, and snippets.

@vmohir
Created December 9, 2020 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmohir/90db795344e2dd4987a5e0a4ff99a1ef to your computer and use it in GitHub Desktop.
Save vmohir/90db795344e2dd4987a5e0a4ff99a1ef to your computer and use it in GitHub Desktop.
SoundCloud useful buttons
function docReady(fn) {
if (
document.readyState === "complete" ||
document.readyState === "interactive"
) {
setTimeout(fn, 1);
} else {
document.addEventListener("DOMContentLoaded", fn);
}
}
var funcs = [addShuffleLikesBtn, addClearLongTracksBtn];
var onDocReady = () => {
funcs.forEach((f) => {
let success = f();
if (success) return;
setTimeout(f, 2000);
});
};
try {
setTimeout(function () {
docReady(onDocReady);
}, 3000);
} catch (e) {
console.error(e);
}
function addBtn(btnText, func) {
var filterSearch = document.querySelector(".header__right");
if (!filterSearch) return false;
var btn = document.createElement("button");
btn.id = "custom shuffle like";
btn.classList.add("sc-button", "sc-button-cta");
btn.style = "margin: 10px 2px; float: left;";
btn.innerText = btnText;
filterSearch.insertAdjacentElement("afterbegin", btn);
btn.addEventListener("click", func);
return true;
}
function addShuffleLikesBtn() {
return addBtn("shuffle", function () {
var playlist = document.querySelector(".queue__scrollableInner");
var shuffleButton = document.querySelector(".shuffleControl");
let int = setInterval(() => {
playlist.scrollTop = playlist.scrollHeight;
}, 700);
setTimeout(() => {
clearInterval(int);
if (shuffleButton.classList.contains("m-shuffling")) {
shuffleButton.click();
setTimeout(function () {
shuffleButton.click();
});
} else {
shuffleButton.click();
}
}, 65000);
});
}
function addClearLongTracksBtn() {
return addBtn("clearlong", function clearLongTracks() {
[...document.querySelectorAll(".queue__itemWrapper")]
.filter((item) => {
const time = item.querySelector(`.queueItemView__duration`).innerText;
const t = time.split(":");
return t.length > 2 || parseInt(t[0], 10) > 10;
})
.forEach((item) => {
const removeBtn = item.querySelector(".queueItemView__remove");
if (removeBtn) removeBtn.click();
});
});
}
@vmohir
Copy link
Author

vmohir commented Dec 9, 2020

The shuffle button is a better shuffle button the built-in one. It'll shuffle all lazy loaded songs in the tracklist.

The clearlong button is useful when you want to remove long dj mix tracks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment