Spotify Web - Copy playlist info

Copy playlist info for export

  1. // ==UserScript==
  2. // @name Spotify Web - Copy playlist info
  3. // @description Copy playlist info for export
  4. // @namespace cobr123
  5. // @version 2.9
  6. // @license MIT
  7. // @grant GM.setClipboard
  8. // @grant GM_setClipboard
  9. // @include https://open.spotify.com/*
  10. // ==/UserScript==
  11.  
  12.  
  13. function copyPL() {
  14. let svPlayList = '';
  15.  
  16. document.querySelectorAll('div[data-testid="tracklist-row"] > div:nth-child(2) > div').forEach(row => {
  17. let svTrackName = row.querySelector('div').textContent;
  18. let svArtistName = row.querySelector('span').textContent;
  19. if(row.querySelectorAll('span').length > 2) {
  20. svArtistName = row.querySelector('span:nth-child(3)').textContent
  21. }
  22. let svTrackInfo = svTrackName + ' - ' + svArtistName;
  23. console.log(svTrackInfo);
  24. svPlayList += svTrackInfo + '\n';
  25. });
  26. GM_setClipboard(svPlayList);
  27. alert('Copied:\n' + svPlayList);
  28. }
  29. function copyPLwithTime() {
  30. let svPlayList = '';
  31. document.querySelectorAll('div[data-testid="tracklist-row"] > div:nth-child(2) > div').forEach(row => {
  32. let svTrackName = row.querySelector('div').textContent;
  33. let svArtistName = row.querySelector('span').textContent
  34. if(row.querySelectorAll('span').length > 2) {
  35. svArtistName = row.querySelector('span:nth-child(3)').textContent
  36. }
  37. let svTrackTime = row.parentElement.parentElement.querySelector('div:nth-child(5) > div').textContent;
  38. let svTrackInfo = svTrackTime + ' ' + svTrackName + ' - ' + svArtistName;
  39. console.log(svTrackInfo);
  40. svPlayList += svTrackInfo + '\n';
  41. });
  42. GM_setClipboard(svPlayList);
  43. alert('Copied:\n' + svPlayList);
  44. }
  45.  
  46. let bindEvents = function () {
  47. document.querySelector('div[data-testid="action-bar-row"]').innerHTML += '<button id="copy_playlist_to_clipboard" class="btn btn-green false">Copy playlist to clipboard</button>';
  48. document.querySelector('div[data-testid="action-bar-row"]').innerHTML += '<button id="copy_playlist_to_clipboard_with_time" class="btn btn-green false">Copy playlist to clipboard with time</button>';
  49. document.getElementById('copy_playlist_to_clipboard_with_time').onclick = copyPLwithTime;
  50. document.getElementById('copy_playlist_to_clipboard').onclick = copyPL;
  51. };
  52.  
  53. window.setTimeout(bindEvents, 1000);