Created
April 24, 2024 08:20
-
-
Save alexander-danilenko/1cd07b7bb47b1714753fa922bc4da13f to your computer and use it in GitHub Desktop.
Tempermonkey: Copy Apple Music playlist information | Export Apple Music playlist to text
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
// ==UserScript== | |
// @name Apple music - Copy playlist info | |
// @description Copy playlist information in format `${index}. ${artist} - ${title}` | |
// @namespace Alex Danilenko | |
// @version 1.0 | |
// @license MIT | |
// @grant GM.setClipboard | |
// @grant GM_setClipboard | |
// @match https://music.apple.com/* | |
// ==/UserScript== | |
"use strict"; | |
(function () { | |
function copyInfo() { | |
let tracks = []; | |
let rows = document.querySelectorAll('.songs-list-row'); | |
rows.forEach(function(row, index) { | |
const title = row.querySelector('.songs-list-row__song-name').textContent.replace("\n","").trim(); | |
const artist = row.querySelector('.songs-list__col--secondary a').textContent.replace("\n","").trim(); | |
const album = row.querySelector('.songs-list__col--tertiary a').textContent.replace("\n","").trim(); | |
tracks.push({index: index + 1, title, artist, album}); | |
}); | |
console.log(tracks) | |
const formattedStrings = tracks.map(({index, title, artist, album}) => `${index}. ${artist} - ${title}`) | |
GM_setClipboard(formattedStrings.join("\n")); | |
alert('Copied:\n' + formattedStrings.join("\n")); | |
} | |
let bindEvents = function () { | |
let button = document.createElement('button'); | |
button.id = "copy_playlist_to_clipboard"; | |
button.className = "product-controls__button link"; | |
button.textContent = "Copy playlist to clipboard"; | |
button.addEventListener('click', function(){ | |
copyInfo(); | |
}); | |
document.querySelector("div.primary-actions").appendChild(button); | |
}; | |
window.setTimeout(bindEvents, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment