Greasy Fork is available in English.

TirexoFullDL

Telecharger tout les lien sur Tirexo

Från och med 2021-10-22. Se den senaste versionen.

// ==UserScript==
// @name         TirexoFullDL
// @namespace    https://greasyfork.org/fr/users/11667-hoax017
// @version      2.2.0
// @description  Telecharger tout les lien sur Tirexo
// @author       Hoax017
// @match        https://**/**
// @screen       http://prntscr.com/1qu4dun
// @screen       http://prntscr.com/1wrl8ud
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==
(async function() {
    'use strict';
    let protectUrls = [
        "journaldupirate.net",
        "decotoday.net",
        "buzzfil.org",
        "hyipstats.net",
        "berich.ai"
    ];
    let msgerror;
    if ((msgerror = document.querySelector('html body div div h1')) && (msgerror.innerText == "403" || msgerror.innerText == "Error 520")) {
        setTimeout(_ => location.reload(true), 3000)
    }
    protectUrls = JSON.parse(GM_getValue("protectUrls", null)) || protectUrls;
    if (protectUrls.some(domain => location.hostname.includes(domain))) { // descript links
        if(document.querySelector('input[value="Continuer pour voir le lien"]')) {
            if (document.querySelector('span#captcha img')) {
                console.info("captcha needed");
                function getBase64Image(img) {
                    var canvas = document.createElement("canvas");
                    canvas.width = img.width;
                    canvas.height = img.height;
                    var ctx = canvas.getContext("2d");
                    ctx.drawImage(img, 0, 0);
                    var dataURL = canvas.toDataURL("image/png");
                    return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
                }
                const k = "db753f23fcf2214d8cec18a66f1d85da"

                const responseIdRaw = await fetch("https://2captcha.com/in.php", {
                    method: "POST",
                    body: JSON.stringify({
                        key: k,
                        header_acao: 1,
                        method: "base64",
                        body: getBase64Image(document.querySelector("span#captcha img"))
                    })
                });
                const responseId = (await responseIdRaw.text()).split("|")
                if (!responseId || responseId.length !== 2) return ;
                if (responseId[0] !== "OK") return ;
                const id = responseId[1];

                let resolutionValue = null
                while (!resolutionValue) {
                    await new Promise(resolve => setTimeout(resolve, 1000));
                    const responseResolveRaw = await fetch(`https://2captcha.com/res.php?key=${k}&action=get&id=${id}&header_acao=1`);
                    const responseResolve = (await responseResolveRaw.text()).split("|")

                    if (!responseResolve || responseResolve.length !== 2) continue ;
                    if (responseResolve[0] !== "OK") continue ;
                    resolutionValue = responseResolve[1]
                }
                document.querySelector('span#captcha ~ div input').value = resolutionValue
            }
            document.querySelector('input[value="Continuer pour voir le lien"]').click()
        } else if (document.querySelector('.alert a')) {
            var link = document.querySelector('div.alert a')
            link.href = link.href.replace(/(\?|&)af=\d+/,'').replace(/(\?|&)aff_id=\d+/,'')
            link.textContent = link.href;
            window.opener.parent.postMessage({ link : link.href },"*");
            window.close();
        } else if (document.querySelector(".message") && document.querySelector(".message").textContent.trim() === "Page Expired") {
            setTimeout(location.reload, 2000);
        } else if (document.querySelector("h2").innerText === "404 Page not found") {
            if (location.pathname.indexOf("/fr/") === 0) {
                location = location.pathname.substr(3)
            } else {
                alert("Lien invalide");
                window.close();
            }
        }

    } else if (location.hostname.includes("tirexo.")) { // get all links
        let finalHostDlLinks = [];
        window.addEventListener("message", function (message) {
            if(!protectUrls.some(domain => message.origin.includes(domain))) return ;
            console.log("Getting URL", message.data.link)
            finalHostDlLinks.push(message.data.link)
        });

        const editProtectLinkButton = $("ul.navbar-item ~ li.nav-item").first().clone().appendTo($("ul.navbar-item ~ li.nav-item").parent());
        editProtectLinkButton.find(".fa").removeClass().addClass("fa fa-wrench")
        editProtectLinkButton.find("a").attr("href", "#").click(_ => {
            $("#modal_links #modal_title").text(protectUrls.length)
            $("#modal_links #modal_body").val(protectUrls.join("\n"))
            $("#modal_links").on("hide.bs.modal", _ => {
                protectUrls = $("#modal_links #modal_body").val().split("\n").filter(e=>e)
                GM_setValue("protectUrls", JSON.stringify(protectUrls));
                $("#modal_links").off("hide.bs.modal")
            })
            $("#modal_links").modal()
            new ClipboardJS('.btn');
        })
        editProtectLinkButton.find("span:last-child").text("Editer les sites")

        const onDownloadAll = (async function() {
            let $parent = $(this).parents('.table-responsive');
            let nbChecked = $parent.find('tbody input[type="checkbox"]:checked').length
            let nbRows = $parent.find('tbody tr').length
            let dlAll = !nbChecked
            let alreadyDL = [];
            if (dlAll) {
                $parent.find('select').val(100).change()
                await new Promise((end) => setTimeout(end, 2000));
            }
            finalHostDlLinks = [];
            let closedWindow = 0;
            let nbNotOpened = 0;
            let notCheckedCount = 0;
            $parent.find("tbody tr").each(async (i, tr) => {
                if (!dlAll && !(tr.querySelector('input[type="checkbox"]') || {checked: false}).checked) {
                    notCheckedCount++;
                    return;
                }
                let a = tr.querySelector('a.download[data-id]')
                let linktitle = a.text.trim();
                console.log(linktitle)
                if (~alreadyDL.indexOf(linktitle)) {
                    closedWindow++;
                    return ;
                }
                alreadyDL.push(linktitle);
                let win
                await (new Promise(function(resolve, reject){
                    let superinter = setInterval(function(){
                        if(i - closedWindow > 19) return;
                        console.log(a.href)
                        win = open(a.href);
                        if (!win) {
                            alert("Impossible d'ouvrir la fenetre, pensez a autoriser les popups navigateur");
                            closedWindow++;
                            nbNotOpened++;
                            reject();
                        } else {
                            resolve()
                        }
                        clearInterval(superinter)
                    }, (dlAll ? i : i - notCheckedCount) * 2000)
                }));
                let interval = setInterval(function () {
                    if (win && win.closed) {
                        closedWindow++;
                        if (closedWindow + notCheckedCount === $parent.find("a.download[data-id]").length) {
                            setTimeout(_ => {
                                $("#modal_links #modal_title").text(finalHostDlLinks.length)
                                $("#modal_links #modal_body").val(finalHostDlLinks.join("\n"))
                                // alert(`${finalHostDlLinks.length} Liens recuperes\n${finalHostDlLinks.join("\n")}`);
                                $("#modal_links").modal()
                                new ClipboardJS('.btn');
                            }, nbNotOpened * 500)
                        }
                        clearInterval(interval);
                    }
                }, 500)
                })
        });
        const init = _ => {
            if ($("button.Hoax_validated").length) return;
            $("tfoot").each(function (){
                let button = $(this).find('button.copy_serie')
                button.parent().prev().append($(`<button class="btn btn-info Hoax_validated" type="button"><i class="fa fa-files-o"></i> Copier tout les liens</button>`).on('click', onDownloadAll))

            });
        };
        setInterval(init, 1000);
        init()
    }
})();