Apple music - Copy playlist info

Copy playlist info for export

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name          Apple music - Copy playlist info
// @description   Copy playlist info for export
// @namespace     cobr123
// @version       1.0
// @license       MIT
// @require       https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
// @grant         GM.setClipboard
// @grant         GM_setClipboard
// @include       https://music.apple.com/*
// ==/UserScript==
 

"use strict";

(function () {
  
  function copyPL() {
    let svPlayList = '';
    $('div[class="tracklist-item__text we-selectable-item__link-text"]').each(function() {
      let row = $(this);
      let svTrackName = $('div:nth-child(1) > a > div > span', row).text().replace("\n","");
      let svArtistName = $('div:nth-child(2) > a', row).text().replace("\n","");
      let svTrackInfo = svTrackName + ' - ' + svArtistName;
      console.log(svTrackInfo);
      svPlayList += svTrackInfo + '\n';
    });
    GM_setClipboard(svPlayList);
    alert('Copied:\n' + svPlayList);
  }
  
  let bindEvents = function () {
    $("div.product-hero-desc--side-bar").after('<button id="copy_playlist_to_clipboard" class="product-controls__button link">Copy playlist to clipboard</button>');
    $('#copy_playlist_to_clipboard').click(function(){
      copyPL();
    });
  };
  
  window.setTimeout(bindEvents, 1000);

})();