下载网易云lrc歌词

下载网易云音乐的歌词(lrc文件格式)

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         下载网易云lrc歌词
// @namespace    https://github.com/0And1Story
// @version      1.0.0
// @description  下载网易云音乐的歌词(lrc文件格式)
// @author       0And1Story
// @match        https://music.163.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function copyLyric() {
        let song_id = window.location.href.match(/song\?id=(\d+)/)[1];
        fetch(`http://music.163.com/api/song/media?id=${song_id}`)
        .then(res => res.json())
        .then(data => {
            console.log(data.lyric);
            const input = document.createElement('textarea');
            document.body.appendChild(input);
            input.value = data.lyric;
            input.setSelectionRange(0, input.value.length);
            input.select();
            document.execCommand('copy');
            document.body.removeChild(input);
            alert('复制成功');
        });
    }

    setTimeout(function() {
        let box = document.querySelector('#user-operation > p.s-fc3');
        box.innerHTML = `<a class="f-tdu s-fc7">复制歌词</a>&nbsp;&nbsp;&nbsp;&nbsp;` + box.innerHTML;
        box.querySelector('a').onclick = copyLyric;
    }, 500);
})();