Summarize Rapidgator links

Summarize Rapidgator links and display them with a copy button.

Per 28-02-2025. Zie de nieuwste versie.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==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);
})();