Kits4Beats & PasteIndex Auto Download Opener

Automatically opens download links on kits4beats.com and pasteindex.com kit pages, bypassing countdowns and CAPTCHAs where possible.

// ==UserScript==
// @name         Kits4Beats & PasteIndex Auto Download Opener
// @namespace    http://tampermonkey.net/
// @license MIT
// @version      1.2.1.64
// @description  Automatically opens download links on kits4beats.com and pasteindex.com kit pages, bypassing countdowns and CAPTCHAs where possible.
// @author       .gg/kits4leaks
// @match        https://kits4beats.com/*
// @match        https://pasteindex.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=kits4beats.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const openedLinks = new Set();

    // Function to handle kits4beats.com
    const handleDownloadLink = (anchorOrUrl) => {
        const url = typeof anchorOrUrl === 'string' ? anchorOrUrl : anchorOrUrl.href;
        if (!openedLinks.has(url)) {
            console.log(`[Tampermonkey] Opening download link: ${url}`);
            window.open(url, '_blank');
            openedLinks.add(url);
        }
    };
    const handleKits4Beats = () => {
        const initialLink = document.querySelector('a#download');
        if (initialLink) handleDownloadLink(initialLink);

        const observer = new MutationObserver((mutations) => {
            for (const mutation of mutations) {
                mutation.addedNodes.forEach(node => {
                    if (node.nodeType === 1) { // element
                        const anchor = node.querySelector && node.querySelector('a#download');
                        if (anchor) handleDownloadLink(anchor);

                        if (node.id === 'download' && node.tagName === 'A') {
                            handleDownloadLink(node);
                        }
                    }
                });
            }
        });

        observer.observe(document.body, { childList: true, subtree: true });
    };

    // Function to handle pasteindex.com
    const handlePasteIndex = () => {
        const rawUrl = new URLSearchParams(window.location.search).get('url');
        if (rawUrl) {
            const decodedUrl = decodeURIComponent(rawUrl);
            if (decodedUrl) {
                handleDownloadLink(decodedUrl);
                return;
            }
        }
        const checkForDownloadLink = () => {
            const rawUrlDiv = document.querySelector('div.raw-url#rawDisplay');
            if (rawUrlDiv) {
                const anchor = rawUrlDiv.querySelector('a');
                if (anchor && anchor.href) {
                    handleDownloadLink(anchor);
                    return true; 
                }
            }
            return false;
        };
        if (checkForDownloadLink()) return;
        const maxAttempts = 50;
        let attempts = 0;
        const interval = setInterval(() => {
            if (checkForDownloadLink() || attempts >= maxAttempts) {
                clearInterval(interval);
            }
            attempts++;
        }, 100);
        const observer = new MutationObserver((mutations) => {
            if (checkForDownloadLink()) {
                observer.disconnect();
                clearInterval(interval);
            }
        });

        observer.observe(document.body, { childList: true, subtree: true });
    };
    if (window.location.hostname === 'kits4beats.com') {
        handleKits4Beats();
    } else if (window.location.hostname === 'pasteindex.com') {
        handlePasteIndex();
    }
})();