Skip to content

Instantly share code, notes, and snippets.

@vmohir
Last active September 19, 2020 06:46
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/2355e701580e070d41c3eed90be68575 to your computer and use it in GitHub Desktop.
Save vmohir/2355e701580e070d41c3eed90be68575 to your computer and use it in GitHub Desktop.
SoundCloud Better Shuffle
/**
* This script adds a button to soundcloud web that will simulate a scroll to the playlist and finally shuffles it.
* This way, it'll shuffle all the musics
*/
function docReady(fn) {
if (
document.readyState === "complete" ||
document.readyState === "interactive"
) {
setTimeout(fn, 1);
} else {
document.addEventListener("DOMContentLoaded", fn);
}
}
var onDocReady = () => {
var success = addSuffleLikesBtn();
if (success) return;
setTimeout(onDocReady, 5000);
};
try {
setTimeout(function(){docReady(onDocReady);},3000);
} catch(e) {
console.error(e)
}
function addSuffleLikesBtn() {
var filterSearch = document.querySelector(".header__right");
console.log(filterSearch);
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 = "shuffle current";
filterSearch.insertAdjacentElement("afterbegin", btn);
btn.addEventListener("click", 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();
}
}, 20000);
});
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment