Greasy Fork

来自缓存

阿童木种子一键认领/取消认领

阿童木一键认领种子或取消认领种子,因网站魔力不增加,但认领照常发放而给出的解决方案,进入网站后点击自己的ID进入个人页面,稍等片刻就会出现相关内容,操作间隔为1秒,请耐心等待操作全部完成。

// ==UserScript==
// @name         阿童木种子一键认领/取消认领
// @version      1.0
// @author       PoppyGuy
// @description  阿童木一键认领种子或取消认领种子,因网站魔力不增加,但认领照常发放而给出的解决方案,进入网站后点击自己的ID进入个人页面,稍等片刻就会出现相关内容,操作间隔为1秒,请耐心等待操作全部完成。
// @match        *://hdatmos.club/userdetails.php?id=*
// @license      MIT
// @icon         https://hdatmos.club/favicon.ico
// @grant        none
// @namespace https://greasyfork.org/users/1304869
// ==/UserScript==

(function() {
    var style = document.createElement('style');
    style.innerHTML = `
        .seed-table {
            width: 100%;
            border-collapse: collapse;
            border-radius: 5px;
            overflow: hidden;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            margin-bottom: 20px;
            border: 1px solid #ddd;
        }

        .seed-table th,
        .seed-table td {
            border: 1px solid #ddd;
            padding: 10px;
            text-align: center;
        }

        .seed-table th {
            background-color: #f2f2f2;
        }

        .seed-table tr:nth-child(even) {
            background-color: #f9f9f9;
        }

        .seed-table tr:hover {
            background-color: #f1f1f1;
        }

        .seed-table thead {
            font-weight: bold;
        }

        .seed-table tbody tr:last-child {
            border-bottom: 2px solid #ddd;
        }

        .seed-table tbody tr:hover {
            background-color: #f0f0f0;
        }

        .claim-buttons {
            text-align: center;
            margin-bottom: 15px;
        }

        .claim-button {
            display: inline-block;
            padding: 10px 20px;
            margin-right: 10px;
            background-color: orange;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        .claim-button:hover {
            background-color: darkorange;
        }
    `;
    document.head.appendChild(style);

    function sleep(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }

    function claimSeed(seedIdList) {
        seedIdList.forEach(async (seedId, index) => {
            await sleep(1000); // Wait for 1 seconds between requests
            fetch('https://hdatmos.club/ajax.php', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                body: 'action=addClaim&params%5Btorrent_id%5D=' + seedId
            })
            .then(response => response.text())
            .then(data => {
                console.log('认领种子ID成功:', seedId);
            })
            .catch(error => console.error('认领种子ID出错:', error));
        });
    }

    // 获取当前页面网址
    var currentURL = window.location.href;

    // 匹配网址中的 id 值
    var matches = currentURL.match(/id=([0-9]+)/);

    if (matches && matches.length > 1) {
        var idValue = matches[1];
        console.log("当前页面的 id 值为:", idValue);

        // 构建新的请求 URL
        var requestURL = `https://hdatmos.club/getusertorrentlistajax.php?userid=${idValue}&type=seeding`;

        // 使用 fetch 获取网页源码
        fetch(requestURL)
            .then(response => response.text())
            .then(data => {
                var parser = new DOMParser();
                var doc = parser.parseFromString(data, 'text/html');

                var torrentIds = doc.querySelectorAll('[data-torrent_id]');

                // 使用 Set 来存储唯一的种子 ID
                var uniqueIds = new Set();

                torrentIds.forEach(torrentId => {
                    uniqueIds.add(torrentId.getAttribute('data-torrent_id'));
                });

                // 创建表格来展示唯一的种子 ID
                var table = document.createElement('table');
                table.classList.add('seed-table');

                // 创建表头
                var headerRow = table.createTHead().insertRow();
                var headerIndexCell = headerRow.insertCell(0);
                var headerIdCell = headerRow.insertCell(1);

                headerIndexCell.textContent = '序号';
                headerIdCell.textContent = '种子ID';

                var numRows = Math.max(20, uniqueIds.size);

                // 添加表格数据
                Array.from(uniqueIds).forEach((id, index) => {
                    var row = table.insertRow();
                    var indexCell = row.insertCell(0);
                    var idCell = row.insertCell(1);

                    indexCell.textContent = index + 1;
                    idCell.textContent = id;
                });

                // 添加空行以确保总行数为20
                for (var i = uniqueIds.size; i < numRows; i++) {
                    var emptyRow = table.insertRow();
                    var emptyCell = emptyRow.insertCell(0);
                    emptyCell.colSpan = 2;
                    emptyCell.textContent = '';
                }

                document.body.appendChild(table);
    let tableDiv = document.createElement('div');
    tableDiv.style.textAlign = 'center';

    // 创建按钮
    var buttonsDiv = document.createElement('div');
    buttonsDiv.classList.add('claim-buttons');

    var claimButton = document.createElement('button');
    claimButton.classList.add('claim-button');
    claimButton.textContent = '一键认领种子';
    claimButton.addEventListener('click', function() {
        claimSeed(Array.from(uniqueIds));
    });

    var cancelClaimButton = document.createElement('button');
    cancelClaimButton.classList.add('claim-button');
    cancelClaimButton.textContent = '一键取消认领';
    cancelClaimButton.addEventListener('click', function() {
        console.log('取消认领种子功能');
  // 在取消认领按钮的事件监听中添加逻辑
    fetch('https://hdatmos.club/claim.php?uid=' + idValue)
        .then(response => response.text())
        .then(data => {
            var parser = new DOMParser();
            var doc = parser.parseFromString(data, 'text/html');

            var claimIds = Array.from(new Set([...doc.querySelectorAll('[data-claim_id]')]
                .map(claimId => claimId.getAttribute('data-claim_id'))
                .filter(Boolean)));

            console.log("唯一的 data-claim_id 值:", claimIds);

            claimIds.forEach((claimId, index) => {
                setTimeout(() => {
                    fetch('https://hdatmos.club/ajax.php', {
                        method: 'POST',
                        headers: {
                            'Content-Type': 'application/x-www-form-urlencoded',
                        },
                        body: 'action=removeClaim&params%5Bid%5D=' + claimId
                    })
                    .then(response => response.text())
                    .then(data => {
                        console.log('成功取消认领,data-claim_id:', claimId);
                    })
                    .catch(error => console.error('取消认领出错:', error));
                }, index * 1000); // 按顺序每1秒执行一次
            });
        })
        .catch(error => console.error("获取源码发生错误:", error));
    });

    buttonsDiv.appendChild(claimButton);
    buttonsDiv.appendChild(cancelClaimButton);

    tableDiv.appendChild(buttonsDiv);
    document.body.insertBefore(tableDiv, document.body.firstChild); // 在表格之前插入按钮
    document.body.appendChild(table);
            })
            .catch(error => console.error("发生错误:", error));
    } else {
        console.log("未找到 id 值");
    }
})();