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 许可证保护。
// @include http://music.163.com/*
// @grant none
// @version 1.1
// @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 = 'http://music.ocrosoft.com/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 'http://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.createLink('歌曲');
var lyricLink = this.createLink('歌词');
api.detail([songId], function(result) {
mp3Link.download = $(tit).children('.f-ff2')[0].innerText;
mp3Link.href = result.mp3Url + ';';
});
api.media(songId, function(result) {
if (result.lyric) {
lyricLink.href = 'data:text/plain;charset=utf-8,' +
encodeURIComponent(result.lyric);
} else {
disableStyle(lyricLink);
}
});
var container = this.createLineContainer('下载');
container.appendChild(mp3Link);
container.appendChild(lyricLink);
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;
},
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.indexOf(page.url) === 0) {
page.handler();
}
}
});
}