磁力快显

在磁力宝、BTSOW、无极磁链ØMagnet等的搜索列表增加磁力链接显示,方便快速下载资源。

当前为 2024-11-05 提交的版本,查看 最新版本

// ==UserScript==
// @name         磁力快显
// @author       zxf10608
// @version      3.3
// @homepageURL  https://gf.qytechs.cn/zh-CN/scripts/397490
// @icon      	 https://cdn.jsdelivr.net/gh/zxf10608/JavaScript/icon/magnet00.png
// @description  在磁力宝、BTSOW、无极磁链ØMagnet等的搜索列表增加磁力链接显示,方便快速下载资源。
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @include      *://clb*.*
// @include      *://sobt*.*
// @include      *://www.btmov*
// @include      *://*mag.net/search*
// @include      *://btsow*/search/*
// @include      *://skrbtzz.top/search*
// @include      *://www.*yuhuage*.*/search/*
// @grant        GM_xmlhttpRequest
// @connect      *
// @grant        GM_setClipboard
// @grant        GM_notification
// @grant        GM_openInTab
// @run-at       document-end
// @compatible   chrome
// @license      GPL License
// @namespace http://tampermonkey.net/
// ==/UserScript==

(function() {
	
	var mag_href = location.href.match(/mag\.net|yuhuage/);
	var clb_href = document.title.indexOf('磁力宝');
	
	if (mag_href == null){//非mag.net或yuhuage
		$(document).ready(function(){
			$('.common-link:odd,.search-tips,#cps-wrap').remove();//删除广告
			$('a:not([href^="magnet:"])').each(function(){
				var reg = /(^|\/|&|-|\.|\?|=|:)([a-fA-F0-9]{40})/;
				var link = $(this).attr('href') || '';
				if(reg.test(link)){
					$(this).attr('target','_blank');
					var newLink = 'magnet:?xt=urn:btih:' + link.match(reg)[2];
					$(this).after('<img src="https://cdn.jsdelivr.net/gh/zxf10608/JavaScript/icon/magnet00.png" class="mag1" href='+newLink+' title="识别到磁力链接,左键打开,右键复制\n'+newLink+'" target="_blank" style="z-index:9123456789;display:inline-block;cursor:pointer;margin:0px 5px 2px;border-radius:50%;border:0px;vertical-align:middle;outline:none!important;padding:0px!important;height:20px!important;width:20px!important;left:0px!important;top:0px!important;">');
				
				};
			});
		});
		setTimeout(function(){
			if($('.115offline').length>0){
				$('.mag1').remove();//隐藏图标
			};
		},500);
	}else{
		function magnetCall(href){//获取数据
			return new Promise(function(resolve, reject){
				GM_xmlhttpRequest({
					method: 'GET',
					url: href,
					onload: function(data,status) {
						if(data.readyState==4 && data.status==200){
							var htmlTxt = data.responseText;
							resolve(htmlTxt);//成功返回函数
						};	
					},
					onerror: function(error) {
						reject(error);//失败返回函数
					},
				});
			});
		};
		
		var magnetEl = $('a[href*="/!"],a[href*="hash"],a[href*="detail"],a[url]');//识别异步超链接,无则不循环  
		console.log('磁力链接有'+magnetEl.length+'个');
		$(document).ready(function(){
			magnetEl.attr({'target':'_blank','style':'display:inline-block;'});
		});
		
		if (magnetEl.length<20){//循环次数
			var n = magnetEl.length; 
		}else{
			var n = 20; 
		};

        let arr = [];   //promise返回值的数组
        for (let i = 0; i < n; i++) {//异步多线程 i是循环体内局部作用域,不受外界影响。
			var link = magnetEl.eq(i).attr('href');
			if (mag_href != null) {//缩写网址补全
				link = location.origin+link;
				//console.log(link);
			};
						
			magnetCall(link).then(function(htmlTxt){
				arr[i] = new Promise((resolve, reject) => {
					var newLink = htmlTxt.match(/href="(magnet.{54}).*"/);
					if (newLink != null ) {
						magnetEl.eq(i).after('<img src="https://cdn.jsdelivr.net/gh/zxf10608/JavaScript/icon/magnet00.png" class="mag1" href='+newLink[1]+'  title="识别到磁力链接,左键打开,右键复制\n'+newLink[1]+'" target="_blank" style="z-index:9123456789;display:inline-block;cursor:pointer;margin:0px 5px 2px;border-radius:50%;border:0px;vertical-align:middle;outline:none!important;padding:0px!important;height:20px!important;width:20px!important;left:0px!important;top:0px!important;">');
						//console.log(newLink[1]);
					}else{
						console.log(link+' 磁力链接不存在');
					};
					resolve(i);//该异步已完成
				});
            });
        };
		
        Promise.all(arr).then((res) => {//all所有异步已执行 
			console.log('磁力链接已全部加载完成。');
        }).catch((err) => {
            console.log('磁力链接加载失败');
        });

	};	
	
	$('body').on('contextmenu click','.mag1', function(e) {
		var link=$(this).attr('href')
		if(e.type == 'click'){//左键 
			GM_openInTab(link,false);
		}else{//右键
			GM_setClipboard(link);
			/* GM_notification({
				title:'磁力快显:',
				text:'磁力链接复制成功!',
				timeout:2000,
			}); */
			console.log('磁力链接复制成功:\n'+link);
		};	
		return false;
	});
	
})();

QingJ © 2025

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