-
-
Save AgentRev/54dd02e1dc97be2f9df72f5336a9721a to your computer and use it in GitHub Desktop.
Copy SoundCloud playlist items from one to another, and add user tracks to playlist
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
const WAIT_OPEN_PLAYLIST_POPUP = 1000; | |
const WAIT_AFTER_ADD_PLAYLIST = 1500; | |
const PLAYLIST_NAME = 'Target'; | |
const listItems = Array.from(document.querySelectorAll('.sc-button-group.sc-button-group-small:first-child')); | |
const addItemToPlaylist = (index) => { | |
const node = listItems[index]; | |
if (!node) { | |
console.log('Done with all currently loaded items.'); | |
return; | |
} | |
const hasLikedButton = node.querySelector('.sc-button-like.sc-button-selected'); | |
if (hasLikedButton) { | |
console.log('Already liked index: ', index); | |
setTimeout(() => { | |
addItemToPlaylist(index + 1); | |
}, 0); | |
return; | |
} | |
node.querySelector('.sc-button-more').click(); | |
document.querySelector('button.sc-button-addtoset').click(); | |
setTimeout(() => { | |
const playlistRow = Array.from(document.querySelectorAll('.addToPlaylistList__item')).find(node => node.querySelector(`[title="${PLAYLIST_NAME}"]`)); | |
const playListButton = playlistRow.querySelector('button.addToPlaylistButton:not(.sc-button-selected)'); | |
if (!playListButton) { | |
console.log('Already added index: ', index); | |
setTimeout(() => { | |
addItemToPlaylist(index + 1); | |
}, 0); | |
return; | |
} | |
playListButton.click(); | |
console.log('Added index: ', index); | |
setTimeout(() => { | |
addItemToPlaylist(index + 1); | |
}, WAIT_AFTER_ADD_PLAYLIST); | |
}, WAIT_OPEN_PLAYLIST_POPUP); | |
}; | |
addItemToPlaylist(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment