Greasy Fork is available in English.

AnnuaireTelechargement Full DL

Ajoute un boutton pour recuperer tous les liens decodes

// ==UserScript==
// @name        AnnuaireTelechargement Full DL
// @namespace   https://greasyfork.org/fr/users/11667-hoax017
// @match       https://www.annuaire-telechargement.*/?p=serie*
// @match       https://dl-protect.link/*
// @grant       none
// @version     2.1.1
// @author      Hoax017
// @license     MIT
// @description Ajoute un boutton pour recuperer tous les liens decodes
// ==/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 = $(`
        <div class="modal" id="${id}" tabindex="-1" role="dialog" style="display: none;" aria-hidden="true">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Liste des liens (<span id="modal_title"></span>)</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true"><span class="masha_index masha_index164" rel="164"></span>×</span>
                </button>
              </div>
              <div class="modal-body" id="info_modal_links">
              <form>
                <div class="form-group">
                  <textarea class="form-control" name="repot" id="modal_body" style="height: 400px;"></textarea>
                </div>
              </form>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Fermer</button>
                <button type="button" class="btn btn-primary" id="copyLinks">Copier les liens</button>
              </div>
            </div>
          </div>
        </div>`);
        $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 $(`<a href="#" class="btn btn-outline-primary px-3" style="float:right;"><img src="https://www.svgrepo.com/show/528952/download.svg" height="15px"></a>`)
            .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() {
      document.querySelector(".fiche center a").remove()
      var dataset = {}

      $(".list-group-item.list-group-item-action.justify-content-between").each((index, elem) => {

          let span = elem.querySelector("span span")
          if (span.title === "Premium") {
            span.remove()
            elem.remove()
          }
          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){
        const $url =  $(".container .text-center a").first()
        const url = $url.attr("href").replace(/[&?]af(f)?=[^&]+/, '')
        $url.attr("href", url)
        $url.text(url)
        window.opener.postMessage({
          url: url,
          id: location.pathname.replace("/",'')
        }, "*");
      }
    }
}

if (location.host.includes(".annuaire-telechargement."))
  Scrapper.setupAnnuaire()
else if (location.host === "dl-protect.link")
  Scrapper.setupDlProtect()