bt4g添加磁力链接

在BT4G搜索页面标题后直接添加磁力链接跳转链接

Versione datata 22/04/2022. Vedi la nuova versione l'ultima versione.

// ==UserScript==
// @name         bt4g添加磁力链接
// @namespace    [email protected]
// @version      0.1.0
// @description  在BT4G搜索页面标题后直接添加磁力链接跳转链接
// @match        *://*.bt4g.org/search/*
// @author       Xiccnd

// @license      GPL-3.0 License

// @require https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js
// @icon         https://cdn.jsdelivr.net/gh/Xiccnd/Xiccnd-Pic@master/20220421113011992.1vh7zbll47r4.ico
// @grant        none
// ==/UserScript==

$(function () {

    'use strict'

    /*
    * 开启或关闭脚本功能
    * */
    //开启添加磁力链接
    xiccndAddMagnet()

    /*
    * 添加磁力链接功能
    * */
    function xiccndAddMagnet() {
        //在标题后添加
        $('h5 a').on('mouseover', function () {//鼠标悬停事件
            //判断是否已添加a标签
            if (!($(this).next().length > 0)) {
                //获取链接
                const URL = $(this).attr('href')
                //合成磁力链接
                const SRC = 'magnet:?xt=urn:btih:' + URL.substr(8)
                //生成a标签
                const A = '<a style="color: red" target="_blank">磁力链接</a>'
                //添加a标签
                $(this).parent('h5').append(A)
                //a标签绑定事件
                $(this).next().on('click', function () {
                    //a标签添加磁力链接
                    $(this).attr('href', SRC)
                }).on('mouseover', function () {
                    $(this).css('cursor', 'pointer').css('color', 'pink')
                }).on('mouseout', function () {
                    $(this).css('color', 'red')
                })
            }
        }).trigger('mouseover')//全部触发
    }
})