// ==UserScript== // @name 网易云音乐灰色歌曲一键导出 (纯净版) // @namespace http://tampermonkey.net/ // @version 1.2 // @description 在网易云右下角添加红色悬浮按钮,一键导出变灰歌曲(仅歌名和歌手)为 CSV 表格。 // @author Gemini // @license MIT // @match *://music.163.com/* // @grant none // @icon https://s1.music.126.net/style/favicon.ico // ==/UserScript== (function() { 'use strict'; if (window !== window.top) return; // 1. 创建悬浮按钮 const btn = document.createElement('button'); btn.innerHTML = '📥 导出灰色歌曲'; btn.style.cssText = ` position: fixed; bottom: 30px; right: 30px; z-index: 99999; padding: 12px 20px; background-color: #d33a31; color: white; border: none; border-radius: 8px; font-size: 14px; font-weight: bold; cursor: pointer; box-shadow: 0 4px 6px rgba(0,0,0,0.3); transition: background-color 0.2s; `; btn.onmouseover = () => btn.style.backgroundColor = '#c23028'; btn.onmouseout = () => btn.style.backgroundColor = '#d33a31'; // 2. 核心逻辑 btn.onclick = function() { const iframe = document.getElementById('g_iframe'); if (!iframe) { alert('请先进入具体的歌单页面哦!'); return; } try { const doc = iframe.contentDocument || iframe.contentWindow.document; const disabledRows = doc.querySelectorAll('tr.js-dis'); if (disabledRows.length === 0) { alert('当前页面没有加载出变灰的歌曲,请确保已经下滑到底部加载完毕!'); return; } let csvContent = '\uFEFF歌名,歌手\n'; disabledRows.forEach(row => { const songEl = row.querySelector('.ttc b'); const songName = songEl ? songEl.getAttribute('title') : '未知歌名'; const artistEl = row.querySelector('td:nth-child(4) .text'); const artistName = artistEl ? artistEl.getAttribute('title') : '未知歌手'; csvContent += `"${songName}","${artistName}"\n`; }); // 3. 触发下载 const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = `网易云失效歌曲_${new Date().getTime()}.csv`; link.style.display = 'none'; // 【关键修复代码】:阻止点击事件向上冒泡,防止网易云拦截 link.addEventListener('click', function(e) { e.stopPropagation(); }); document.body.appendChild(link); link.click(); document.body.removeChild(link); URL.revokeObjectURL(url); } catch (error) { console.error('抓取数据时出错了:', error); alert('抓取失败,请检查控制台报错!'); } }; document.body.appendChild(btn); })();