Skip to content

Instantly share code, notes, and snippets.

@3rogue
Last active May 3, 2024 15:11
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save 3rogue/23c7bc2f876070dc3e956441e3d55a01 to your computer and use it in GitHub Desktop.
Save 3rogue/23c7bc2f876070dc3e956441e3d55a01 to your computer and use it in GitHub Desktop.
网易云音乐歌词下载(双语喔)
// ==UserScript==
// @name 网易云歌词下载,可以双语了orz
// @namespace http://suselinks.us
// @description 我只是做了合并了两个脚本的工作,可以直接下载了。
// @description 脚本1:https://greasyfork.org/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
// @description 脚本2:https://gist.github.com/anonymous/a800677393bbb2dd113a 多谢他们
// @include http://music.163.com/*
// @grant none
// @version 1.2
// ==/UserScript==
var api = {
mediaUrl: function(songId) {
return 'http://music.163.com/api/song/lyric?lv=-1&tv=-1&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.getElementById('g_iframe');
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];
console.log(albumNode);
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 lyricLink = this.createLink('歌词');
api.media(songId, function(result) {
var newLrc = [];
var lrc = result.lrc.lyric.match(/\[\d+:\d+\.\d+[^\[]+/g);
if (result.tlyric.lyric) {
var tLrc = result.tlyric.lyric.match(/\[\d+:\d+\.\d+[^\[]+/g);
newLrc = lrc.concat(tLrc);
}else {
newLrc = lrc;
}
lyricLink.href = "data:text/text;charset=UTF-8,"+ encodeURIComponent(newLrc.join('\n'));
var innerFrameDoc = innerFrame.contentWindow.document;
var singer = innerFrameDoc.querySelector('p.des.s-fc4>span').title;
var singer_concat = singer.match(/[^/ ]+/g).join(',');
var songname = innerFrameDoc.querySelector('em.f-ff2').innerHTML;
var filename = singer_concat + ' - ' + songname + '.lrc';
lyricLink.setAttribute('download', filename);
});
var container = this.createLineContainer('下载');
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:void(0);';
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();
}
}
});
}
@3rogue
Copy link
Author

3rogue commented Dec 14, 2016

此版本只能下载歌词

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment