// ==UserScript==
// @name AnnuaireTelechargement Full DL
// @namespace https://greasyfork.org/fr/users/11667-hoax017
// @match https://www.annuaire-telechargement.ink/?p=serie*
// @match https://dl-protect.link/*
// @grant none
// @version 1.0
// @author Hoax017
// @license MIT
// @description Ajoute un boutton pour recuperer tous les liens decodes
// @downloadURL none
// ==/UserScript==
/* jshint esversion:8 */
const waitElem = (selector, speed = 500, maxTime = 30000, errorFn = _ => _) => new Promise(function (resolve) {
let maxIteration = maxTime / speed;
let inter = setInterval(async _ => {
if (document.querySelector(selector)) {
clearInterval(inter)
resolve()
}
maxIteration--
if (maxIteration < 0) {
clearInterval(inter);
if (typeof errorFn === 'function') errorFn();
}
}, speed);
});
const addModal = (id) => {
const $modal = $(`
`);
$modal.on("click", "#copyLinks", function () {
navigator.clipboard.writeText($(this).parents(".modal").find(`textarea#modal_body`).val())
})
$modal.get(0).update = function (links = []) {
$(this).find(`textarea#modal_body`).val(links.join("\n"))
$(this).find(`span#modal_title`).text(links.length)
}
$modal.on("hide.bs.modal", function () {
this.update()
$(this).off("hide.bs.modal")
})
$("body").append($modal)
}
class Scrapper {
static createButton(data) {
return $(`
`)
.click(async (event) => {
window.addEventListener('message', function(e) {
let link = data.links.find(link => link.url.includes(`/${e.data.id}?fn=`))
link.fetched = e.data.url;
} , false);
const $modal = $('body').find("#modal_link")
$modal.modal("show")
let tab = open("", '_blank')
for (let link of data.links) {
if (link.fetched) continue;
console.log(`Open ${link.url}`)
tab.location = link.url
await new Promise(resolve => {
let inter = setInterval(_ => {
if (link.fetched || tab.closed) {
clearInterval(inter)
return resolve()
}
}, 300)
})
if (tab.closed) break;
$modal[0].update(data.links.reduce((acc, link) => [...acc, link.fetched], []).filter(Boolean))
}
tab.close()
$modal[0].update(data.links.reduce((acc, link) => [...acc, link.fetched], []).filter(Boolean))
$modal.modal("show")
})
}
static setupAnnuaire() {
var dataset = {}
$(".list-group-item.list-group-item-action.justify-content-between").each((index, elem) => {
let span = elem.querySelector("span span")
if (!dataset.hasOwnProperty(span.title)) {
let $header = $(elem).prev();
dataset[span.title] = { header: $header.get(0), links: [] }
$header.append(Scrapper.createButton(dataset[span.title]))
}
dataset[span.title].links.push({url: elem.href, fetched: null})
});
addModal("modal_link")
}
static async setupDlProtect() {
if ($("#subButton").length) {
await waitElem("#subButton:not([disabled])")
$("#subButton").click()
}
if ($(".container .text-center a").length){
window.opener.postMessage({
url: $(".container .text-center a").first().attr("href").replace(/[&?]af(f)?=[^&]+/, ''),
id: location.pathname.replace("/",'')
}, "*");
}
}
}
if (location.host === "www.annuaire-telechargement.ink")
Scrapper.setupAnnuaire()
else if (location.host === "dl-protect.link")
Scrapper.setupDlProtect()