// ==UserScript== // @name XMwiki专辑曲目列表生成 // @version 1.6.2 // @description 几个常用音乐平台专辑曲目列表生成 Grab song list information from some websites // @author XMAnon // @icon https://s1.ax1x.com/2020/07/15/UabtVe.jpg // @match *://www.amazon.com/* // @match *://www.amazon.de/* // @match *://www.amazon.fr/* // @match *://www.amazon.it/* // @match *://www.amazon.es/* // @match *://music.apple.com/* // @match *://open.spotify.com/* // @match *://www.deezer.com/* // the script is mostly inspired by Jeffrey.Deng(https://greasyfork.org/users/129338)复制spotify歌曲名脚本 // Grabbing Info from other sites is almost similar. // 音乐平台抓取歌曲列表,并生成符合XM格式的歌曲列表(页面2) // Supported: // Spotify Album, // Amazon Free Streaming and MP3 Site (tested on US/DE, other Countries should also work) may not working properly after amazon website update // Apple Music // Deezer // To be done: // Multiple CD case, Bandcamp, MusicBrainz // // @namespace https://greasyfork.org/users/666548 // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Your code here... function copyToClipboard(text) { if (window.clipboardData && window.clipboardData.setData) { // IE specific code path to prevent textarea being shown while dialog is visible. return clipboardData.setData("Text", text); } else if (document.queryCommandSupported && document.queryCommandSupported("copy")) { var textarea = document.createElement("textarea"); textarea.textContent = text; textarea.style.position = "fixed";// Prevent scrolling to bottom of page in MS Edge. document.body.appendChild(textarea); textarea.select(); try { return document.execCommand("copy");// Security exception may be thrown by some browsers. } catch (ex) { console.warn("Copy to clipboard failed.", ex); return false; } finally { document.body.removeChild(textarea); } } } var song = function(_title, _artist) { this.title = _title; this.artist = _artist.replace(/ & | feat. |, /gm,';'); }; function checkSrc(currentUrl){ var getSpotify = function(){}; var getAmazon = function(){}; var getApple = function(){}; var getDeezer = function(){}; //var getDeezer = function(){}; //***************************************** Spotify ********************************************************************* getSpotify = function() { var nodes = document.querySelector('#main .tracklist-container .tracklist').childNodes;//querySelectorAll("div > li > div.tracklist-col.name > div > div"); if (!nodes) { console.warn("Songs nodes not found!!"); return; } var playList = []; var len = nodes.length; var charList = ''; for (var i = 0; i < len; i += 1) { var one = new song(nodes[i].querySelector(".tracklist-name").innerText, nodes[i].querySelector(".second-line .ellipsis-one-line").innerText); playList.push(one); charList = charList + one.title + '【歌手】' + one.artist + '\n'; } copyToClipboard(charList); console.log(charList); } //***************************************** Amazon ********************************************************************* getAmazon = function(){//Amazon新的流媒体页面没有曲目艺人信息了所以就只抓取了曲目列表 2020.08 //var nodes = document.querySelector("#dmusic_tracklist_content > tbody").getElementsByClassName('a-text-left a-align-center darkenOnHover');//tested on 'amazon.de' unlimited stream page, but now without artists name var nodes = document.querySelector("#dmusic_tracklist_content > tbody").childNodes;//tested on 'amazon.de' unlimited stream page, but now without artists name //var headerNode = document.getElementById('dmusic_tracklist_header_box'); var len = nodes.length; if (!nodes) { console.warn("nodes not found"); return;} // else if (len === 0){ // nodes = [headerNode.nextSibling.nextSibling]; //Special Case when it's EP // len = 1; // } var playList = []; var albumArtist = document.getElementById("ProductInfoArtistLink").innerText; var charList = ''; for (var i = 0; i < len; i += 2) { //var rawList = (nodes[i].innerText.split('\t')); var title = (nodes[i].querySelector(".TitleLink").innerText); //rawList = rawList.filter(function(e){return e.replace(/\t/gm,"")}); //var one = new song(rawList[1], rawList[2].replace(/ & /gm,';').replace(' feat. ',';').replace(/, /gm,';')); //var one = new song(rawList[1]); var one = new song(title,''); // switch(0){ // case(one.artist.indexOf('\t')): // one.artist = albumArtist; // break; // case(one.artist.indexOf('de ')): // case(one.artist.indexOf('di ')): // case(one.artist.indexOf('by ')): // one.artist = one.artist.substring(3); // break; // case(one.artist.indexOf('von ')): // one.artist = one.artist.substring(4); // break; // } //console.log(rawList); //console.log(one); playList.push(one); //charList = charList + one.title + '【歌手】'+ one.artist + '\n'; charList = charList + one.title + '\n'; } copyToClipboard(charList); console.log(charList); } //***************************************** Apple ********************************************************************* getApple = function() { var nodes = document.querySelector('.product-page .header-and-songs-list .songs-list').querySelectorAll(".song"); if (!nodes) { console.warn("Songs nodes not found!!"); return; } var albumArtist = document.querySelector(".product-page .product-creator").innerText.replace(/ & | feat. /gm,';'); var playList = []; var len = nodes.length; var charList = ''; var artist = ''; for (var i = 0; i < len; i += 1) { var title = nodes[i].querySelector(".song-name-wrapper .song-name").innerText; if (!nodes[i].querySelector(".song-name-wrapper .by-line")){ artist = albumArtist; } else{ artist = nodes[i].querySelector(".song-name-wrapper .by-line").innerText} var one = new song(title, artist); playList.push(one); charList = charList + one.title + '【歌手】' + one.artist + '\n'; } copyToClipboard(charList); console.log(charList); } //***************************************** Deezer ********************************************************************* getDeezer = function() { var nodes = document.querySelector('.page-content .container .datagrid-container .datagrid').querySelectorAll(".song"); if (!nodes) { console.warn("Songs nodes not found!!"); return; } var albumArtist = document.querySelector('.page-content .container .heading-link').innerText.replace(/ & | feat. /gm,';'); var playList = []; var len = nodes.length;//曲目数量 var lenLabeled = document.querySelector('.page-content .container .datagrid-container .datagrid').querySelectorAll(".song .datagrid-label-artist").length var charList = ''; var title = ''; var artist = ''; for (var i = 0; i < len; i += 1) { title = nodes[i].querySelector(".cell-title .title").innerText; if (!nodes[i].querySelector(".datagrid-label-artist")){//没标艺人,即专辑艺人 artist = albumArtist;} else{//标了艺人,feat需加上专辑艺人 if(len > lenLabeled){ var coartist = nodes[i].querySelector(".datagrid-label-artist").innerText; artist = albumArtist + ';' + coartist; } else{ artist = nodes[i].querySelector(".datagrid-label-artist").innerText; } } var one = new song(title, artist); playList.push(one); charList = charList + one.title + '【歌手】' + one.artist + '\n'; } copyToClipboard(charList); console.log(charList); } //var getBandCamp = function(){} //var getMusicBrain = function(){} // //***************************************** Discogs ********************************************************************* // var getDiscogs = function(){//Discogs格式太乱了,情况太多了,写好了三种的,不好用先注释掉了。。。。 // var nodes = document.querySelector("#tracklist > div > table > tbody").querySelectorAll("tr");//[0].innerText; // var len = nodes.length; // if (!nodes) { // console.warn("nodes not found"); // return;} // var playList = []; // var albumArtist = document.getElementById("profile_title").innerText.split(' ‎– ')[0].replace(/ & | feat. |, | And /gm,';').replace(/\*/gm,''); // var song = function(_title,_artist) { // this.title = _title; // this.artist = _artist; // }; // var charList = ''; // for (var i = 0; i < len; i += 1) { // var rawList = (nodes[i].innerText.replace('\n–\n','').split('\t')); // rawList = rawList.filter(function(e){return e.replace(/\n/gm,'')}); // var lenElement = rawList.length; // var one; // switch(lenElement){ // case(4): // one = new song(rawList[2], rawList[1].replace(/ & | feat. |, | And /gm,';').replace(/\*/gm,'')); // break; // case(3): // case(2): // one = new song(rawList[lenElement - 2], albumArtist); // break; // } // ; // console.log(rawList); // console.log(one); // playList.push(one); // charList = charList + one.title + '【歌手】'+ one.artist + '\n'; // } // copyToClipboard(charList); // } // unsafeWindow.getDiscogs = getDiscogs; //********************************************************************************************************************* switch(true){ case (currentUrl.indexOf('open.spotify.com') > -1): getSpotify(); break; case (currentUrl.indexOf('www.amazon') > -1): getAmazon(); break; case (currentUrl.indexOf('music.apple.com') > -1): getApple(); break; case (currentUrl.indexOf('www.deezer.com') > -1): getDeezer(); break; //case (currentUrl.indexOf('bandcamp') > -1): // case (currentUrl.indexOf('discogs.com') > -1): // newBtn.onclick = getDiscogs; // newBtn.style.backgroundColor = 'white'; // var title_Discogs = document.getElementById("profile_title"); //Button near the title // title_Discogs.appendChild(newBtn); //break; default: console.warn('Host not matching'); } } //**************打印下键盘事件的event对象********** // document.onkeydown = function (oEvent) { // console.log(oEvent);} // ************************************************ document.onkeydown = function(oEvent) {//快捷键Shift + C 触发命令 oEvent = oEvent || window.oEvent; //获取键盘的keyCode值 var nKeyCode = oEvent.keyCode // || oEvent.which || oEvent.charCode; //获取shift 键对应的事件属性 var bShiftKeyCode = oEvent.shiftKey //|| oEvent.metaKey; if(nKeyCode == 67 && bShiftKeyCode) {//快捷键 shift + c : shift(shiftKey) c(keyCode = 67; which = 67; charCode = 0 ) x(keyCode = 88;which = 88; charCode = 0 ) //doSomeThing... //alert('you punched shift + c'); var currentUrl = window.location.href; checkSrc(currentUrl);//check source and get song list } } })();