javdb auto open

增加页面顶部底部按钮和一键下种按钮

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name         javdb auto open
// @namespace    websiteEnhancement
// @author   jimmly
// @version      2026.9.2
// @description  增加页面顶部底部按钮和一键下种按钮
// @create         2023-9-21
// @include        *javdb*
// @grant         GM_getValue
// @grant         GM_setValue
// @grant         GM.getValue
// @grant         GM.setValue
// @grant        GM_xmlhttpRequest
// @grant        GM_log
// @connect      nas.knewbeing.com
// @license MIT
// @run-at document-idle
// ==/UserScript==

(async function (loadJQuery) {

    loadJQuery(window).then(([$, win]) => {
        $.ajaxSetup({
            cache:true
        });
        ["https://cdn.jsdelivr.net/npm/[email protected]/jquery.lazyload.min.js",
         "https://cdn.jsdelivr.net/gh/sodiray/radash@master/cdn/radash.min.js",
         // "https://update.greasyfork.org/scripts/483173/1301961/GM_config_cnjames.js",
         // "https://raw.githubusercontent.com/sizzlemctwizzle/GM_config/refs/heads/master/gm_config.js",
         "https://cdn.jsdelivr.net/gh/sizzlemctwizzle/GM_config@master/gm_config.js",
         "https://update.sleazyfork.org/scripts/476583/common_libs_of_array.js",
         // "https://update.sleazyfork.org/scripts/513894/1470715/remove%20ads%20lib.js",
         // "https://update.sleazyfork.org/scripts/513894/1627441/remove%20ads%20lib.js",
         // "https://update.sleazyfork.org/scripts/513894/1627444/remove%20ads%20lib.js", //with version
         "https://update.sleazyfork.org/scripts/513894/remove%20ads%20lib.js" //no version
        ].reduce((p, url) => p.then(() => new Promise((resolve, reject) => $.getScript(url).done(() => resolve()).fail((er) =>{console.log(er)}))), Promise.resolve())
            .then(v=>remove_adds($, window))
            .then(v => {

            const config = {
                baseUrl: 'http://nas.knewbeing.com:8085',
                user: 'admin',
                pwd: 'adminadmin',
                paused: false
            };

            const formHeaders = {'Content-Type': 'application/x-www-form-urlencoded'};

            const httpReq = options => new Promise((resolve, reject) => {
                GM_xmlhttpRequest({
                    ...options,
                    timeout: 15_000,
                    onload: response => {
                        if (response.status >= 200 && response.status < 300 && response.responseText === 'Ok.') {
                            resolve(response);
                            return;
                        }

                        reject(new Error(`qBittorrent request failed: HTTP ${response.status} ${response.responseText}`));
                    },
                    onerror: () => reject(new Error('Unable to reach qBittorrent Web UI.')),
                    ontimeout: () => reject(new Error('qBittorrent Web UI request timed out.'))
                });
            });

            // 登录
            const login = () => httpReq({
                method: 'POST',
                url: `${config.baseUrl}/api/v2/auth/login`,
                headers: formHeaders,
                data: new URLSearchParams({username: config.user, password: config.pwd}).toString()
            });

            // 添加磁力任务
            const addTask = magnet => httpReq({
                method: 'POST',
                url: `${config.baseUrl}/api/v2/torrents/add`,
                headers: formHeaders,
                data: new URLSearchParams({urls: magnet, paused: String(config.paused)}).toString()
            });

            const sendMagnet = async magnet => {
                if (!magnet) {
                    throw new Error('No magnet link was found on this page.');
                }

                await login();
                return addTask(magnet);
            };

            window.sendMagnet = sendMagnet;
            win.funcDownload =function () {
                const torrentUrl = $('div.magnet-name.column.is-four-fifths>a').first().prop('href');

                sendMagnet(torrentUrl)
                    .then(() => {
                    if (localStorage.getItem("autoclosewindow") == 'Auto') {
                        window.close();
                        //window.open("about:blank", "_self").close();
                    }
                })
                    .catch(err => {
                    console.error('Failed to add torrent:', err);
                    alert('任务添加失败,请检查 qBittorrent 配置和网络连接。');
                });



            }
            // win.funcList = function () { }
            // win.funcDetail = function () { }
            // const reg = /.*thread-(\d+)-.*/
            // win.__compareKey = function (cache, curr) {
            //     if (cache === curr)
            //         return true
            //     ///thread-6638382-
            //     if (reg.test(cache))
            //         return cache.replace(reg, "$1") === curr
            //     return false
            // }
            // win.fixValue = function (value) {
            //     if (reg.test(value))
            //         return value.replace(reg, "$1")
            //     return value
            // }
            $('table a').removeAttr('style')
            win.actionOpened=function(el){
                const item =el.closest('.item')
                item.hide()
                try{
                    item.parent().remove(item)
                }
                catch{
                    try{
                        item.remove()
                    }
                    catch{

                    }

                }

            }
            //autoFind(funcIsListPage, cmgId, selector, funcText, $, elBindOpen, unsafeWindow, funcDownload, funcList, funcDetail,actionOpened)
            autoFind(() => ['/', '/tags', '/tags/uncensored'].includes(window.location.pathname), 'javdb', '.item a', el => el.attr('title'), $, {}, win);


        })
    })

})(function (unsafeWindow) {
    return new Promise((resolve, reject) => {
        let dollar
        if (typeof $ != "undefined"){
            console.log('no found $')
            dollar = $
            if($.noConflict)
                $.noConflict()
        }
        if (typeof jQuery == "undefined" || typeof jQuery.fn =="undefined" ||typeof jQuery.fn.lazyload=="undefined") {
            console.log('no found jQuery, loading jquery-3.7.1')
            let script = document.createElement("script")
            script.type = "text/javascript"
            script.src = "https://code.jquery.com/jquery-3.7.1.min.js"
            script.onerror = function () {
                reject(new Error("Failed to load jQuery"))
            }
            script.addEventListener("load", function () {
                jQuery.noConflict()
                if (dollar) $ = dollar;

                resolve([jQuery, unsafeWindow??window])
            })

            document.head.appendChild(script)
        }
        else {
            setTimeout(function () {
                // Firefox supports
                if (dollar) $ = dollar;

                resolve([$, unsafeWindow??window])
            }, 30)
        }
    })
});