网易云音乐列表导出

导出当前页网易云音乐列表

目前为 2018-02-23 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 网易云音乐列表导出
  3. // @namespace undefined
  4. // @version 0.0.1
  5. // @description 导出当前页网易云音乐列表
  6. // @author allen smith
  7. // @match *://music.163.com/*
  8. // @require https://cdn.bootcss.com/clipboard.js/1.7.1/clipboard.js
  9. // @run-at document-end
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. // 检测页面
  17. var htm = document.getElementsByClassName('f-oh');
  18. if(htm.length === 0){
  19. return;
  20. }
  21.  
  22. // 检测文档变动
  23. var doc = document.getElementById('g_mymusic');
  24. var _body = document.body;
  25. var clipboard, btn, spli, interId ;
  26. doc.addEventListener('DOMSubtreeModified', function () {
  27. //检测列表
  28. var list = document.getElementsByClassName('m-table')[0];
  29. if (!list) {
  30. btn = document.getElementById('export-btn');
  31. spli = document.getElementById('export-spli');
  32. if(btn) _body.removeChild(btn);
  33. if(spli) _body.removeChild(spli);
  34. return;
  35. }
  36.  
  37. //创建按钮
  38. btn = null;
  39. spli = null;
  40. btn = document.getElementById('export-btn');
  41. spli = document.getElementById('export-spli');
  42. if (!spli) {
  43. spli = document.createElement("input");
  44. spli.id = 'export-spli';
  45. spli.className = 'export-spli';
  46. spli.setAttribute('placeholder','输入分割符,空格有效');
  47. spli.setAttribute('style', 'display:inline-block;position:absolute;right:50px;top:100px;padding:3px 5px;border:1px solid lightgray;background-color:white;color:black;border-radius:5px;font-size:14px;');
  48. _body.appendChild(spli);
  49. }
  50. if (!btn) {
  51. btn = document.createElement("button");
  52. btn.id = 'export-btn';
  53. btn.className = 'export-btn';
  54. btn.innerText = '导出列表';
  55. btn.setAttribute('style', 'display:inline-block;position:absolute;right:50px;top:130px;padding:3px 5px;border:1px solid lightgray;background-color:white;color:black;border-radius:5px;font-size:14px;');
  56. _body.appendChild(btn);
  57. }
  58.  
  59. //创建剪贴板
  60. if (clipboard) clipboard.destroy();
  61. clipboard = new Clipboard('.export-btn', {
  62. text: function (trigger) {
  63.  
  64. //导出列表
  65. btn.innerText = '正在导出 ...';
  66. var result = '';
  67. var listBody = list.getElementsByTagName('tbody')[0];
  68. var rows = listBody.getElementsByTagName('tr');
  69. for (var i = 0; i < rows.length; i++) {
  70. var ele = rows[i];
  71. var cells = ele.getElementsByTagName('td');
  72. var name = cells[1].getElementsByTagName('b')[0].getAttribute('title').replace(/<div class="soil">[\s\S\n]*?<\/div>/g, "").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&");
  73. var artist = cells[3].getElementsByTagName('span')[0].getAttribute('title').replace(/<div class="soil">[\s\S\n]*?<\/div>/g, "").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&");
  74. var album = cells[4].getElementsByTagName('a')[0].getAttribute('title').replace(/<div class="soil">[\s\S\n]*?<\/div>/g, "").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&");
  75.  
  76. var spliChar = spli.value;
  77. if(!spliChar.trim()) spliChar = ' -- ';
  78. result += name + spliChar + artist + spliChar + album + '\r\n';
  79. }
  80.  
  81. //提示动画
  82. btn.innerText = '已复制到剪贴板 =';
  83. var count = 6;
  84. clearInterval(interId);
  85. interId = setInterval(function () {
  86. count--;
  87. if (count > 0)
  88. btn.innerText = '已复制到剪贴板 ' + waitAnimationChar(count);
  89. else{
  90. btn.innerText = '导出列表';
  91. clearInterval(interId);
  92. }
  93. }, 300);
  94.  
  95. //输出到控制台
  96. console.log(result);
  97. //输出到剪贴板
  98. trigger.setAttribute('aria-label', result);
  99. return trigger.getAttribute('aria-label');
  100. }
  101. });
  102.  
  103. //字符动画
  104. var waitAnimationChar = function(n){
  105. var temp = n % 3;
  106. if(temp === 0) return '#';
  107. else if(temp == 1) return '$';
  108. else if(temp == 2) return '+';
  109. };
  110. });
  111. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址