Created
December 9, 2020 16:39
-
-
Save vmohir/90db795344e2dd4987a5e0a4ff99a1ef to your computer and use it in GitHub Desktop.
SoundCloud useful buttons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.