Skip to content

Instantly share code, notes, and snippets.

@cassdeckard
Created May 18, 2018 15:25
Show Gist options
  • Select an option

  • Save cassdeckard/694c7459474f24f11450ac1694758ef4 to your computer and use it in GitHub Desktop.

Select an option

Save cassdeckard/694c7459474f24f11450ac1694758ef4 to your computer and use it in GitHub Desktop.
// Setup
var tracklistObj = {},
currentPlaylist,
checkIntervalTime = 100,
lastTime;
// Process the visible tracks
function getVisibleTracks() {
var playlist = document.querySelectorAll('.song-table tr.song-row');
for(var i = 0; i < playlist.length ; i++) {
var l = playlist[i],
title = l.querySelector('td[data-col="title"] .column-content').textContent,
artist = l.querySelector('td[data-col="artist"] .column-content').textContent,
album = l.querySelector('td[data-col="album"] .column-content').textContent,
// Add it if it doesn't exist already
entry = artist + " - " + title + ' - ' + album;
if (printTrace && i == 1) {
//console.log(entry);
//console.log(currentPlaylist);
}
if(tracklistObj[currentPlaylist] && !tracklistObj[currentPlaylist].includes(entry)) {
tracklistObj[currentPlaylist].push(entry);
if(printTracksToConsole) {
console.log(entry);
}
}
}
}
// Listen for page changes
window.onhashchange = function(e) {
currentPlaylist = null;
var doneLoading = setInterval(function() {
var playListName = document.querySelector('.gpm-detail-page-header h2[slot="title"]');
if(playListName != null) {
currentPlaylist = playListName.innerText;
if(tracklistObj[currentPlaylist] === undefined) {
tracklistObj[currentPlaylist] = [];
}
console.log("===================================");
console.log("Adding to playlist " + currentPlaylist);
getVisibleTracks();
clearInterval(doneLoading);
} else {
console.log('NULL PLAYLIST')
}
}, 100);
}
// Check for new tracks every so often
setInterval(function() {
getVisibleTracks();
}, checkIntervalTime);
// Whether or not to print the tracks obtained to the console
var printTracksToConsole = true;
var printTrace = false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment