FindDownloadLink

侦测页面中的磁力链接&&下载地址并生成到按钮中

  1. // ==UserScript==
  2. // @name FindDownloadLink
  3. // @namespace https://lilopusic.github.io/
  4. // @version 0.1
  5. // @description 侦测页面中的磁力链接&&下载地址并生成到按钮中
  6. // @author hnayan
  7. // @grant GM_addStyle
  8. // @require https://cdn.bootcss.com/zepto/1.2.0/zepto.min.js
  9. // @require https://cdn.bootcss.com/clipboard.js/2.0.1/clipboard.min.js
  10. // @include http://*
  11. // @include https://*
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. addStyle();
  16. new ClipboardJS('.getAll');
  17. class RenderButton {
  18. constructor($, $dom, $a) {
  19. this.$dom = $dom;
  20. this.$a = $a;
  21. this.$ = $;
  22. this.map = new Map();
  23. }
  24. push(name, href) {
  25. if (!this.map.has(name)) {
  26. this.map.set(name, []);
  27. }
  28. this.map.get(name).push(href);
  29. }
  30. render() {
  31. for (let name of this.map.keys()) {
  32. this.appendButton(name, this.map.get(name));
  33. }
  34. }
  35. appendButton(name, list) {
  36. if (list.length !== 0) {
  37. this.$dom.append(`<button data-clipboard-text="${list.join('\n')}" title="Total: ${list.length}" class="getAll" id="get${name}">Get All ${name}.</button>`);
  38. }
  39. }
  40. init() {
  41. let $ = this.$;
  42. $('body').append($container);
  43. for (let i = 0; i < this.$a.length; i++) {
  44. let href = $($a[i]).attr('href');
  45. if (href.startsWith('ed2k')) {
  46. this.push('Ed2k', $($a[i]).attr('href'));
  47. }
  48. if (href.startsWith('magnet')) {
  49. this.push('Magnet', $($a[i]).attr('href'));
  50. }
  51. if (href.startsWith('thunder')) {
  52. this.push('Thunder', $($a[i]).attr('href'));
  53. }
  54. if (href.endsWith('exe')) {
  55. this.push('Exe', $($a[i]).attr('href'));
  56. }
  57. if (href.endsWith('zip') || href.endsWith('rar')) {
  58. this.push('Zip', $($a[i]).attr('href'));
  59. }
  60. }
  61. }
  62. }
  63. const $a = $('a[href]');
  64. const $container = $('<div id="getAllPanel" style="position: fixed;right: -50px;top: 100px;z-index: 9999"></div>');
  65. const renderButton = new RenderButton($, $container, $a);
  66. renderButton.init();
  67. renderButton.render();
  68.  
  69. function addStyle(){
  70. GM_addStyle('.getAll {right:0px;transition: right .5s;position:relative;min-width:100%;margin:5px 0;background-color:white;display: block;padding:10px 15px;border: 1px solid #eee;border-bottom-color: #ddd;-webkit-border-radius: 3px;-webkit-box-shadow: 0 1px 3px #eee;-moz-border-radius: 3px;-moz-box-shadow: 0 1px 3px #eee;border-radius: 100px 0 0 100px;outline: none;cursor: pointer;}');
  71. GM_addStyle('.getAll:hover {right: 50px;}');
  72. }
  73. })();