Summarize Rapidgator links

Summarize Rapidgator links and display them with a copy button.

Versión del día 28/02/2025. Echa un vistazo a la versión más reciente.

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         Summarize Rapidgator links
// @namespace    http://tampermonkey.net/
// @version      0.97
// @description  Summarize Rapidgator links and display them with a copy button.
// @author       Setcher
// @match        https://rapidgator.net/folder/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=rapidgator.net
// @grant        GM_setClipboard
// ==/UserScript==

(function() {
    'use strict';

    // Function to extract and prepend links
    function extractAndDisplayLinks() {
        // Find the container div where we want to insert the new div (summary div)
        let summaryDiv = document.querySelector('.summary');

        if (!summaryDiv) return;  // If summary div is not found, do nothing

        // Create a new div under the summary div with the 'table_header' class
        let newDiv = document.createElement('div');
        newDiv.setAttribute('class', 'btm');  // Set the class to table_header

        // Heading for the new div
        let heading = document.createElement('div');
        heading.innerHTML = "Rapidgator Links";  // Simplified heading
        newDiv.appendChild(heading);

        // Create a table for displaying the links
        let table = document.createElement('table');
        table.classList.add('items');  // Apply the 'items' class for consistent styling

        // Add table header row
        let thead = document.createElement('thead');
        let headerRow = document.createElement('tr');
        let nameHeader = document.createElement('th');
        nameHeader.textContent = "File Name";
        let sizeHeader = document.createElement('th');
        headerRow.appendChild(nameHeader);
        thead.appendChild(headerRow);
        table.appendChild(thead);

        // Extract all file links that start with href="/file/"
        let links = document.querySelectorAll('a[href^="/file/"]');
        let tbody = document.createElement('tbody');

        links.forEach(link => {
            let fileLink = link.getAttribute('href');
            if (fileLink && fileLink.startsWith("/file/")) {
                let fullLink = 'https://www.rapidgator.net' + fileLink;

                // Create a new table row for each link
                let row = document.createElement('tr');
                row.setAttribute('class', 'odd');
                let nameCell = document.createElement('td');

                // Create a link in the first cell
                let fileLinkElement = document.createElement('a');
                fileLinkElement.href = fullLink;
                fileLinkElement.textContent = fullLink; // Use the text of the link
                nameCell.appendChild(fileLinkElement);


                row.appendChild(nameCell);
                tbody.appendChild(row);
            }
        });

        // Add the tbody to the table
        table.appendChild(tbody);

        // Add the table to the new div
        newDiv.appendChild(table);

        // Create the "Copy all" button
        let copyButton = document.createElement('button');
        copyButton.textContent = 'Copy all';

        // Button click handler to copy all links to the clipboard
        copyButton.addEventListener('click', function() {
            let allLinks = Array.from(tbody.querySelectorAll('tr')).map(row => {
                let link = row.querySelector('a');
                return link ? link.href : '';
            }).join('\n');
            GM_setClipboard(allLinks);
            alert('Links copied to clipboard!');
        });

        // Add the button below the table
        newDiv.appendChild(copyButton);

        // Append the new div with the table to the summary div
        summaryDiv.appendChild(newDiv);
    }

    // Run the script when the page is fully loaded
    window.addEventListener('load', extractAndDisplayLinks);
})();