// ==UserScript== // @name 动漫花园提取BT磁力链 // @description 提取、选择并复制动漫花园当前搜索结果的BT磁力链 // @require https://code.jquery.com/jquery-3.3.1.min.js // @author YD-Cat // @version 1.5 // @namespace https://greasyfork.org/zh-CN/users/242083-yd-cat // @copyright 2019+, YD-Cat // @include http*://share.dmhy.org/* // @icon https://share.dmhy.org/favicon.ico // @downloadURL none // ==/UserScript== var $ = jQuery.noConflict(); var eventFun=function(){ //显示窗口 $("#extract").click(function(){ var magnetObjs=$('.download-arrow.arrow-magnet') var titleObjs=$('td.title>a') //显示或隐藏 if($('#magnetBox').css('display')!='block'){ //初始化内容 $('#magnetUrl tbody').text('') $('#magnetBox span').text(0) $('#selectAll').attr('flag',false) //没有资源 if(magnetObjs.length<=0||($('#topic_list>tbody>tr[class="mismatch"]').length==$('#topic_list>tbody>tr').length)){ let str='没有资源'; $("#magnetUrl tbody").append(str); show(); } else{ var index=0; titleObjs.each((i,myThis)=>{ const tr =$(myThis).parents('#topic_list>tbody>tr'); if(!tr.hasClass('mismatch')){ let str=''+ ++index +''+titleObjs[i].innerText+''+magnetObjs[i].href.substring(0,magnetObjs[i].href.indexOf('&dn'))+'' $("#magnetUrl tbody").append(str); } }) show(); } } else{ hide(); } }); //全选 $("#selectAll").click(function(){ var flag=stringToBoolean($('#selectAll').attr('flag')) $('#magnetUrl [type="checkBox"]').each(function(){this.checked= !flag}) $('#magnetBox span').text($('#magnetUrl :checked').length) $('#selectAll').attr('flag',!flag) if(stringToBoolean($('#selectAll').attr('flag'))){ $('#magnetUrl tbody>tr').each((i,node)=>{ $(node).addClass('checked'); }); } else{ $('#magnetUrl tbody>tr').each((i,node)=>{ $(node).removeClass('checked'); }); } }); //反选 $('#selectInvert').click(function(){ $('#magnetUrl [type="checkBox"]').each(function(){this.checked=!this.checked}); $('#magnetBox span').text($('#magnetUrl :checked').length); $('#magnetUrl tbody>tr').each((i,node)=>{ $(node).toggleClass('checked'); }); isSelectAll() }); //关闭窗口 $("#close").click(function(){ hide(); }); $(document).keydown((e)=>{if(e.keyCode==27) hide();}) //复制已选 $('#copySelect').click(function(){ let str=''; $('#magnetUrl input').each((i,node)=>{ if(node.checked){ str+=$(node).parent().prev().text()+'\n' } }) copy(str) }); //复制全部 $('#copyAll').click(function(){ let str=''; $('.magnet').each((i, node)=>{ str+=$(node).text()+'\n'; }); copy(str); }); //给选择框绑定事件 $(document).on('click','#magnetUrl [type="checkBox"]',function(event){ event.stopPropagation(); $(this).parents('tr').toggleClass('checked'); $('#magnetBox span').text($('#magnetUrl :checked').length); isSelectAll(); }); $(document).on('click','#magnetUrl tbody>tr',function(){ let checkBox=$(this).find('input')[0]; if(checkBox!=null){ checkBox.checked=!checkBox.checked; $('#magnetBox span').text($('#magnetUrl :checked').length); $(this).toggleClass('checked'); isSelectAll(); } }); //防止输入非正整数 $('#page').keypress(function(e){ return(/[\d]/.test(String.fromCharCode(event.keyCode))) }); //跳转 $('#goToPage').click(function(){ let url='https://share.dmhy.org/topics/list/page/'; let page=$('#page').val(); let localUrl=window.location.href; let KWpoint=localUrl.lastIndexOf('?keyword'); let keyword; if(!(KWpoint>0)){ url+=page; } else{ keyword=localUrl.substring(KWpoint); url+=page+keyword; } window.location.href=url; }); $('#page').keypress(function(){ if(event.keyCode==13){ $('#goToPage').click() } }) //筛选 $('#filter').click(function(){ let regexList try{ regexList=$('#condition').val().split(/[; :,,;]+/).map((r)=>new RegExp(r)); } catch(error){ alert('筛选条件错误,请参考正则表达式') } $('#topic_list>tbody>tr').each(function(){ $(this).removeClass(); const tagA=this.querySelector('.title>a') const select = tagA && regexList.reduce((result, regex) =>{return(result && regex.test(tagA.textContent))}, true); if(select==false){ $(this).addClass('mismatch'); } else{ $(this).removeClass('mismatch'); } $(this).removeClass('even'); $(this).removeClass('odd'); }) $('#topic_list>tbody>tr[class!="mismatch"]').each((i,node)=>{ if(i&1) $(node).addClass('odd') else $(node).addClass('even') }); }) $('#condition').keypress(()=>{ if(event.keyCode==13){ $('#filter').click() } }) }; (function() { //添加样式 var style='' $('.table.clear').before(style) //跳转 var goPage='

 | 

跳轉

前往
'; //筛选 var filter='

 | 

条件

筛选
'; //提取 var ExtractText='

 | 

提取鏈接
' //提取界面 var TextBox='
序列標題磁力鏈接選擇

' addObj('.nav_title .fl:last', goPage); addObj('.nav_title .fl:last', filter); addObj('.nav_title .fl:last', ExtractText); addObj('.table.clear .nav_title:first', TextBox); //加载事件 eventFun(); })(); //String转换为Boolean function stringToBoolean(str){ switch(str.toLowerCase()) { case "true": case "yes": case "1": return true; case "false": case "no": case "0": case null: return false; default: return Boolean(str); } } //复制事件 function copy(str){ str=str.substring(0,str.length-1) $('#copyText').val(str) $('#copyText').select() document.execCommand('copy') } //检测是否全选择 function isSelectAll(){ if(Number($('#magnetBox span').text())==$('#magnetUrl [type="checkBox"]').length){ $('#selectAll').attr('flag',true) } else{ $('#selectAll').attr('flag',false) } } //显示提取窗口 function show(){ $('#magnetBox').fadeIn(200) let left=window.innerWidth/2-$('#magnetUrl')[0].offsetWidth/2; let top=window.innerHeight*0.2; $('#magnetBox').css({ 'left':left, 'top':top }) } function hide(){ $('#magnetBox').stop().fadeOut(200,()=>$('#magnetBox').removeAttr('style')); } //添加对象 function addObj(select,obj){ $(select).after(obj) }