复制spotify歌曲名

打印出网页中spotify的歌曲名,以复制

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        复制spotify歌曲名
// @name:zh     复制spotify歌曲名
// @name:en     print(copy) spotify song names
// @namespace   https://greasyfork.org/users/129338
// @version      1.1
// @description  打印出网页中spotify的歌曲名,以复制
// @description:en  print song names of spotify's playlist.
// @author       Jeffrey.Deng
// @match        http://open.spotify.com/*
// @match        https://open.spotify.com/*
// ==/UserScript==

// @weibo       http://weibo.com/3983281402
// @blog        https://imcoder.site

// 1.1 2020.03.19 fixed bug,请在页面完全加载后执行 printList(); 不然会报  Cannot read property 'querySelectorAll' of null

(function() {
    'use strict';

    // Your code here...
    var printList = function () {
        var nodes = document.querySelector('#main .tracklist-container .tracklist').querySelectorAll("div > li > div.tracklist-col.name > div > div");
		if (!nodes) {
			console.warn("not find the songs nodes!!");
			return;
		}
		var playList = [];
		var song = function(_title, _singer) {
			this.title = _title;
			this['singer • album'] = _singer;
		};
		var len = nodes.length;
		for (var i = 0; i < len; i += 2) {
			var one = new song(nodes[i].innerText, nodes[i+1].innerText.replace(/\n/g, ' '));
			playList.push(one);
		}
		console.table(playList);
    }
    unsafeWindow.printList = printList;
    console.log("Now, you can type \"printList();\" in console, then will get the song names");
})();