// ==UserScript==
// @name 磁力快显
// @author zxf10608
// @version 3.7
// @homepageURL https://greasyfork.org/zh-CN/scripts/397490
// @icon https://cdn.jsdelivr.net/gh/zxf10608/JavaScript/icon/magnet00.png
// @description 在磁力宝、BTSOW、ØMagnet、磁力狗等磁力搜索引擎的搜索列表增加磁力链接显示,方便快速下载资源。
// @require https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js
// @include *://clb*.*/s/*
// @include *://clg*.*/search*
// @include *://www.btmov*.*/so/*
// @include *://*mag.net/search*
// @include *://btsow*/search/*
// @include *://www.*yuhuage*.*/search/*
// @connect *
// @grant unsafeWindow
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_openInTab
// @grant GM_notification
// @grant GM_setClipboard
// @grant GM_xmlhttpRequest
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @run-at document-start
// @license GPL License
// @namespace http://tampermonkey.net/
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
if(document.title.indexOf('磁力宝') != -1){
unsafeWindow.alert=function(){
console.log('已阻止弹窗');
};
};
if(GM_getValue('open')==1){
let close=GM_registerMenuCommand ('关闭复制弹窗通知', function(){
GM_setValue('open',0);
GM_unregisterMenuCommand(close);
location.reload();
});
}else{
let open=GM_registerMenuCommand ('开启复制弹窗通知', function(){
GM_setValue('open',1);
GM_unregisterMenuCommand(open);
location.reload();
});
};
function base32To16(str){
if(str.length % 8 !== 0 || /[0189]/.test(str)){
return str;
};
str = str.toUpperCase();
var bin = "", newStr = "", i;
for(i = 0;i < str.length;i++){
var charCode=str.charCodeAt(i);
if(charCode<65)charCode-=24;
else charCode-=65;
charCode='0000'+charCode.toString(2);
charCode=charCode.substr(charCode.length-5);
bin+=charCode;
};
for(i = 0;i < bin.length;i+=4){
newStr += parseInt(bin.substring(i,i+4),2).toString(16);
};
return newStr;
};
$(document).ready(function(){
if(document.title.indexOf('磁力狗') != -1){
$('.SearchListTitle_list_title a').each(function(){
var link = $(this).attr('href');
var hash= link.substring(13);
hash=base32To16(hash).toUpperCase();
$(this).attr('target','_blank');
var newLink = 'magnet:?xt=urn:btih:' + hash;
$(this).append('
');
});
}else{
$('.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('
');
};
});
};
if($('.mag1').length < 1){
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 = $('h3 a[href!="/"],li a[href!="/"],td a[href!="/"],dd a[href!="/"]');
magnetEl.attr({'target':'_blank','style':'display:inline-block;'});
if (magnetEl.length<20){
var n = magnetEl.length;
}else{
var n = 20;
};
let arr = [];
for (let i = 0; i < n; i++) {
var link = magnetEl.eq(i).attr('href');
if (/^\//.test(link)) {
link = location.origin+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('
');
}else{
console.log(link+' 无磁力链接');
};
resolve(i);
});
});
};
Promise.all(arr).then((res) => {
console.log('磁力链接有'+magnetEl.length+'个。');
console.log('磁力链接已全部加载完成。');
}).catch((err) => {
console.log('磁力链接加载失败。');
});
}else{
console.log('磁力链接有'+$('.mag1').length+'个。');
};
setTimeout(function(){
if($('.115offline').length>0){
$('.mag1').remove();
};
},800);
});
$('body').on('contextmenu click','.mag1', function(e) {
var link=$(this).attr('href')
if(e.type == 'click'){
GM_openInTab(link,false);
}else{
GM_setClipboard(link);
if(GM_getValue('open')==1){
GM_notification({
title:'磁力快显:',
text:'磁力链接复制成功!',
timeout:2000,
});
};
console.log('磁力链接复制成功:\n'+link);
};
return false;
});
})();