// ==UserScript== // @name Enhanced dmhy // @description 为种子列表添加支持迅雷离线的磁链,用明确的文件名直接下载种子,批量导出磁链 // @namespace https://greasyfork.org/users/726 // @include http*://share.dmhy.org/* // @include http*://dl.dmhy.org/* // @version 20151007 // @grant none // @downloadURL none // ==/UserScript== if(location.host=='dl.dmhy.org'){ // 用一个微妙的方法改变下载文件名,其实改名的基本思路就是使用download属性设置文件名,但是download属性似乎只支持同域名下载,所以这里需要在dl.dmhy.org这个域名下生成下载链接 if(location.pathname=='/' && location.hash.indexOf('download')==1){ var json = location.hash.substr(10); json = decodeURIComponent(json); var argv = JSON.parse(json); if(argv){ var link = document.createElement('a'); link.href = argv.link; if (typeof link.download === 'string') { link.download = argv.name; } link.innerHTML = ''; // 这里有一句粗糙的CSS Reset以及一个base64编码的箭头图片 document.documentElement.innerHTML = link.outerHTML; // 替换掉整个页面 } } }else{ // 种子列表页面 (function($){ $('#topic_list>thead>tr>th:nth-child(4)').attr('width', '30px').after('离线种子'); // 在表头中添加两列 var rows = []; function Row(i){ this.id = i; this.tr = $('#topic_list>tbody>tr').eq(i); this.tr.children('td:nth-child(4)').after('  '); // 添加两列 this.link_title = this.tr.find('td.title>a'); // 种子页面链接 this.link_magnet = this.tr.find('.arrow-magnet'); // 原始磁链 this.link_thunder = this.tr.find('.arrow-thunder'); // 离线磁链 this.link_torrent = this.tr.find('.arrow-torrent'); // 种子链接 this.link_thunder.attr('href', this.link_magnet.attr('href').substr(0, 52)); // 将原来的磁链截短,只保留btih this.link_torrent.css('opacity', '.2'); // 将种子链接设置为半透明,表示需要加载 // 当鼠标移入种子链接所在td时 this.link_torrent.closest('td').mouseenter(function(){ if(this.link_torrent_done) return; var href = this.link_torrent.attr('href'); if(href){ // 如果链接已经存在,直接通过iframe显示 var iframe = $(''); iframe.attr('src', href); this.link_torrent.replaceWith(iframe); this.link_torrent_done = true; }else{ // 否则先加载数据 this.loadData(0); } }.bind(this)); } Row.prototype.loadData = function(recursive){ if(recursive) $('.export_current').text(this.id); if(!this.tr.hasClass('loading')){ this.tr.addClass('loading'); // 读取种子页面,以便获取种子的下载链接和文件名 $.get(this.link_title.attr('href'), function(html){ // 为了避免页面元素加载,这里使用正则提取数据而不是DOM var torrent_link = html.match(/dl\.dmhy\.org\/([^"]+)/)[1]; // 下载链接 // 获得文件名,这里需要能够处理包含文件夹的种子 var torrent_name = html.match(/([^>]+?)\s*/)[1]; torrent_name = torrent_name.split('/'); var torrent_with_dir = false; if(torrent_name.length>1) torrent_with_dir = true; this.link_magnet.data('dir', torrent_with_dir); this.link_thunder.data('dir', torrent_with_dir); torrent_name = torrent_name[0]; var dn = 'dn=' + encodeURIComponent(torrent_name); this.link_thunder.attr('href', this.link_thunder.attr('href')+'&'+dn); this.link_magnet.attr('href', this.link_magnet.attr('href').replace(/dn=[^&]*/, dn)); torrent_name = torrent_name+'.torrent'; // 接下来是一些谜一样的代码 // 将下载链接和文件名放入一个对象中 var argv = { link : torrent_link, name : torrent_name, }; // 构造一个指向dl.dmhy.org链接,通过hash传递参数 this.link_torrent.attr('href', 'https://dl.dmhy.org/#download#'+JSON.stringify(argv)); if(!recursive){ this.link_torrent.mouseenter(); }else{ if(this.id+1tbody>tr').length;++i){ rows.push(new Row(i)); } if(rows.length){ var export_loading = false; jQuery('.nav_title>.fl').append(' | 快速导出磁链(可能不包含文件名) | 导出磁链(包含文件名) | 导出磁链(只导出单个文件的磁链)'); function export_blob(file_only){ var text = ''; for(var i=0;i(加载中 ... / '); $('.export_total').text(rows.length); rows[0].loadData(1); }); function on_export_loaded(){ $('.export_loading').remove(); $('#export_full').attr('href', export_blob(0)); $('#export_file').attr('href', export_blob(1)); } } })(jQuery); }