(useless now)1Fichier Redirect to FastDebrid

Save 1fichier link, redirect to FastDebrid and autofill the link.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         (useless now)1Fichier Redirect to FastDebrid
// @namespace    https://violentmonkey.github.io/
// @version      1.5
// @description  Save 1fichier link, redirect to FastDebrid and autofill the link.
// @author       Rust1667
// @match        https://1fichier.com/*
// @match        https://fastdebrid.com/*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// ==/UserScript==

(function() {
    'use strict';

    // Function to check if the Cloudflare captcha is solved
    function checkCloudflareCaptchaSolved() {
        if (document.querySelector('.cf-turnstile') || document.querySelector('#captcha-turnstile')) {
            return unsafeWindow.turnstile && unsafeWindow.turnstile.getResponse().length !== 0;
        }
        return true;
    }

    // Wait for the page to load fully
    window.addEventListener('load', function() {

      const currentUrl = window.location.href;

      // On 1fichier page
      if (currentUrl.includes('1fichier.com') && !currentUrl.endsWith('=') && !document.body.innerText.includes("file has been deleted") && !document.body.innerText.includes("automatically deleted")) {
          GM_setValue('saved1FichierLink', currentUrl);
          window.location.assign('https://fastdebrid.com/');

      // On FastDebrid page
      } else if (currentUrl === 'https://fastdebrid.com/') {

              const fichierOption = document.querySelector('[data-name="1fichier"]');
              if (fichierOption) {
                  fichierOption.click();
              }

              function fillForm() {
                  const savedLink = GM_getValue('saved1FichierLink');
                  if (savedLink) {
                      const inputField = document.querySelector('#link');
                      if (inputField) {
                          inputField.value = savedLink;
                          GM_deleteValue('saved1FichierLink');
                      }
                  }
              }

              function clickDebridButton() {
                  const debridButton = document.querySelector('button.btn-primary');
                  if (debridButton && debridButton.innerText.includes('Debrid my link')) {
                      debridButton.click();
                  }
              }

              // Wait for cloudflare captcha to be solved to fill the form and click the button
              let captchaCheckInterval = setInterval(() => {
                  if (checkCloudflareCaptchaSolved()) {
                      clearInterval(captchaCheckInterval);
                      fillForm();
                      clickDebridButton();
                  }
              }, 1000);



      // On fastdebrid page with link ready for download
      } else if (/https:\/\/fastdebrid.com\/.*/.test(currentUrl)) {
          const shortlinkElement = document.querySelector('a.btn-primary.mx-1')
          const dlLinkElement =  document.querySelector('a.btn-success.mx-1')
          if (shortlinkElement) {window.location.assign(shortlinkElement.href);}
          //else if (dlLinkElement) {window.location.assign(dlLinkElement.href);}
      }
    });

})();