Greasy Fork is available in English.

[downloadly.ir/downloadlynet.ir/p30download.ir] - Extract Batch Links for IDM

Extracts download links for batch download with IDM

// ==UserScript==
// @name         [downloadly.ir/downloadlynet.ir/p30download.ir] - Extract Batch Links for IDM
// @namespace    http://tampermonkey.net/
// @version      1.0.5
// @description  Extracts download links for batch download with IDM
// @author       $um@n
// @match        *://*.downloadlynet.ir/*
// @match        *://*.downloadly.ir/*
// @match        *://*.p30download.ir/*
// @grant        none
// @icon         https://downloadlynet.ir/wp-content/uploads/2021/10/favicon.png
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener("load", () => {
        const postContent = document.querySelector(".single-post .w-post-elm.post_content");
        const downloadBox = document.querySelector("#dlbox");
        const downloadExtensions = ["rar", "exe", "zip", "rpm", "deb", "iso", "pdf", "epub", "docx"];
        let previousDownloadLinks = []; // Keep track of previous download links to detect changes

        // Initial extraction if postContent exists
        if (postContent) {
            const anchors = postContent.querySelectorAll("a");
            extractFunction(anchors);
        }

        // Periodically check for changes in download box
        setInterval(() => {
            if (downloadBox) {
                const anchors = downloadBox.querySelectorAll("a");
                const currentDownloadLinks = Array.from(anchors).map(anchor => anchor.href);

                // Check if there are new download links
                const newDownloadLinks = currentDownloadLinks.filter(link => !previousDownloadLinks.includes(link));
                if (newDownloadLinks.length > 0) {
                    extractFunction(anchors);
                    previousDownloadLinks = currentDownloadLinks;
                }
            }
        }, 1000); // Adjust the interval as needed (in milliseconds)

        function extractFunction(anchors) {
            const downloadLinksArray = [];
            for (let i = 0; i < anchors.length; i++) {
                const anchorLink = anchors[i].href;
                const urlSplits = anchorLink.split(".");
                const extension = urlSplits[urlSplits.length - 1];

                if (downloadExtensions.some(str => extension.includes(str))) {
                    downloadLinksArray.push(anchorLink);
                }
            }

            const batchText = downloadLinksArray.join("\n");
            if (batchText) {
                const div = document.createElement("div");
                const heading = document.createElement("h6");

                div.style = `
                    direction: ltr;
                    position: fixed;
                    z-index: 9999;
                    background-color: white;
                    box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px;
                    top: 25%;
                    font-size: 12px;
                    max-height: 300px;
                    line-height: 18px;
                    overflow-y: auto;
                    padding: 15px;
                    right: 15px;
                    white-space: pre;
                    border-radius: 15px;
                `;

                heading.style.marginBottom = "5px";
                heading.textContent = "Copy and paste it on IDM batch download";

                document.body.appendChild(div);
                div.textContent = batchText;
                div.prepend(heading);
            }
        }
    });
})();