Greasy Fork

Greasy Fork is available in English.

烧包一键认领

一键认领烧包已保种

当前为 2021-11-01 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         烧包一键认领
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  一键认领烧包已保种
// @author       ootruieo
// @match        https://ptsbao.club/userdetails.php?id=*
// @grant        unsafeWindow
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    function sleep(time) {
        return new Promise((resolve) => setTimeout(resolve, time)).catch((e)=>{console.log(e);});
    }

    window.onload = function(){
        var rows = document.querySelectorAll("tr");
        for (var i = 0; i < rows.length; i++) {
            if(rows[i].childElementCount==2 && rows[i].cells[0].innerText=="当前做种"){
                var idClaim = document.getElementById("claimAllTorrents");
                if(idClaim == null){
                    rows[i].cells[1].innerHTML+=('<a id="claimAllTorrents" href="javascript:void(0);" onclick="window.manualClaimTorrents();" style="margin-left:10px;font-weight:bold;color:red" title="认领全部当前做种(运行后无法停止,强制停止可关闭页面)">一键认领</a>');
                    break;
                }
            }
        }
    }

    unsafeWindow.manualClaimTorrents = async function(){
        var msg = "确定要认领全部种子吗?\n\n严正警告:\n请勿短时间内多次点击,否则后果自负!\n请勿短时间内多次点击,否则后果自负!\n请勿短时间内多次点击,否则后果自负!";
        if (confirm(msg)==true){
            var x = document.querySelectorAll("a");
            for (var i = 0; i < x.length; i++) {
                if(x[i].href.indexOf("getusertorrentlistajax") != -1 && x[i].href.indexOf("seeding") != -1) {
                    eval(x[i].href);

                    var seeding = document.getElementById("ka1");
                    var seedingNodes = seeding.childNodes;
                    var retryCount = 0;
                    while(retryCount<5 && seedingNodes.length ==0){
                        await sleep(1000);
                        retryCount += 1;
                        seedingNodes = seeding.childNodes;
                    }

                    var total = 0, success = 0;
                    for(var ti=1;ti<seedingNodes[3].rows.length;ti++){
                        if(success >= 500) {
                            alert("最多只能认领500个种子!");
                            break;
                        }
                        var titleElementA = seedingNodes[3].rows[ti].cells[1].getElementsByTagName('a')[0];
                        var torrentid = titleElementA.href.replace("https://ptsbao.club/","").replace("details.php?id=","").replace("&hit=1","");
                        var result = ajax.gets('claim.php?torrentid=' + torrentid);
                        total += 1;
                        if (result != "claim") {
                            seedingNodes[3].rows[ti].setAttribute("style", "background:LightPink !important");
                        } else {
                            seedingNodes[3].rows[ti].setAttribute("style", "background:LightGreen !important");
                            success += 1;
                        }
                        await sleep(50);
                    }
                    alert(`共计${total}个种子,本次成功认领${success}个。`);
                    var idClaim = document.getElementById("claimAllTorrents");
                    idClaim.parentNode.removeChild(idClaim);
                }
            }
        }
    }
})();