Greasy Fork is available in English.
支持新版(2017/9/9)网易云。在歌曲页面上所属专辑下面会出现歌词和歌曲的下载链接。该脚本受 GPL V2.0 许可证保护。
当前为
// ==UserScript==
// @name 网易云音乐直接下载
// @namespace https://www.ocrosoft.com/
// @description 支持新版(2017/9/9)网易云。在歌曲页面上所属专辑下面会出现歌词和歌曲的下载链接。该脚本受 GPL V2.0 许可证保护。
// @match *://music.163.com/*
// @grant none
// @version 1.3
// @require http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js
// ==/UserScript==
/**
* 修改自 http://greasyfork.icu/zh-CN/scripts/10548-%E7%BD%91%E6%98%93%E4%BA%91%E9%9F%B3%E4%B9%90%E4%B8%8B%E8%BD%BD
* API 源码: https://github.com/Ocrosoft/NetEase_OutChain
* 此脚本开源,API开源,但请不要在未经允许的情况下在其他程序中调用此脚本中的API,在非程序调用且小流量的个人使用场景下可以使用。
**/
var api = {
detailUrl: function(songIds) {
var tpl = (location.href.indexOf('https')==-1?'http://music.ocrosoft.com/GetMusicLink.php?id=${songIds}':'https://www.ocrosoft.com/outchain/GetMusicLink.php?id=${songIds}');
return tpl.replace('${songIds}', songIds.join(','));
},
detail: function(songIds, callback) {
$.ajax({
type: "get",
url: this.detailUrl(songIds),
dataType: "jsonp",
success: function(json){
callback(json);
}
});
},
mediaUrl: function(songId) {
return (location.href.indexOf('https')==-1?'http':'https') + '://music.163.com/api/song/media?id=' + songId;
},
media: function(songId, callback) {
var req = new XMLHttpRequest();
req.open('GET', this.mediaUrl(songId), true);
req.onload = function() {
callback(JSON.parse(this.responseText));
};
req.send();
},
};
var innerFrame = document.querySelector('iframe');
var tit;
var pages = [
{
url: 'http://music.163.com/#/song?id=',
handler: function() {
var songId = location.href.match(/id=([0-9]+)/)[1];
var downloadLine = this.createDownloadLine(songId);
var innerFrameDoc = innerFrame.contentWindow.document;
var albumNode = innerFrameDoc.querySelectorAll('p.des.s-fc4')[1];
tit = innerFrameDoc.querySelectorAll('.tit');
var parentNode = albumNode.parentNode;
parentNode.insertBefore(downloadLine, albumNode.nextElementSibling);
},
createDownloadLine: function(songId) {
var disableStyle = function(link) {
link.text += '(无)';
link.style.color = 'gray';
link.style.textDecoration = 'none';
link.style.cursor = 'auto';
};
var mp3Link = this.createMP3Link();
var mp3Help = this.createLink('如何下载歌曲?');
mp3Help.href = 'javascript:;';
$(mp3Help).click(function(){alert("点击下方播放器最右侧的下载按钮");});
var mp3Error = this.createLink('为什么歌曲下载错误?');
mp3Error.href = 'javascript:;';
$(mp3Error).click(function(){alert("下方播放器如果不显示播放时长说明无法下载");});
var lyricLink = this.createLink('歌词');
api.detail([songId], function(result) {
mp3Link.src = result.mp3Url;
});
api.media(songId, function(result) {
if (result.lyric) {
lyricLink.download = $(tit).children('.f-ff2')[0].innerText + '.lrc';
lyricLink.href = 'data:text/plain;charset=utf-8,' +
encodeURIComponent(result.lyric);
} else {
disableStyle(lyricLink);
}
});
var container = this.createLineContainer('下载');
container.appendChild(lyricLink);
container.appendChild(mp3Help);
container.appendChild(mp3Error);
container.appendChild(document.createElement('br'));
container.appendChild(mp3Link);
return container;
},
createLink: function(label) {
var link = document.createElement('a');
link.innerHTML = label;
link.className = 's-fc7';
link.style.marginRight = '10px';
link.href = 'javascript:;';
return link;
},
createMP3Link: function() {
var link = document.createElement('audio');
link.controls = 'true';
link.innerHTML = '浏览器不支持';
return link;
},
createLineContainer: function(label) {
var container = document.createElement('p');
container.className = 'desc s-fc4';
container.innerHTML = label + ':';
container.style.margin = '10px 0';
return container;
},
},
];
if (innerFrame) {
innerFrame.addEventListener('load', function() {
var i, page;
for (i = 0; i < pages.length; i += 1) {
page = pages[i];
if (location.href.split('://')[1].indexOf(page.url.split('://')[1]) === 0) {
page.handler();
}
}
});
}