Create and Fuck your AI Cum Slut -70% OFF
x

Tool Completed [.user.js] Buzzheavier Autodownloader

Bexa2

Newbie
Aug 13, 2017
64
29
I guess it's because of ads but when I download from buzzheavier I have to click the download link twice, and sometimes it's like nothing happens.

So I made ChatGPT make this script, it'll automatically start the download and show toast messages for what's going on.

JavaScript:
// ==UserScript==
// @name         Auto Fetch HX-Redirect and Download (Toast Edition)
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  Automatically fetch hx-redirect and trigger download, with logs and toast notifications for user feedback on BuzzHeavier.com files.
// @author       Bexa2 (F95ZONE)
// @match        *://*.buzzheavier.com/f/*
// @match        *://*.buzzheavier.com/*
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  const SELECTOR = 'a.link-button.gay-button[hx-get]';

  function showToast(message, type = 'info', duration = 5000) {
    const toast = document.createElement('div');
    toast.textContent = message;
    toast.style.cssText = `
      position: fixed;
      bottom: 20px;
      left: 50%;
      transform: translateX(-50%);
      background: ${type === 'error' ? '#f87171' : type === 'success' ? '#4ade80' : '#60a5fa'};
      color: white;
      padding: 10px 20px;
      border-radius: 10px;
      font-size: 14px;
      box-shadow: 0 2px 8px rgba(0,0,0,0.3);
      z-index: 9999;
      opacity: 0;
      transition: opacity 0.3s ease;
    `;
    document.body.appendChild(toast);
    requestAnimationFrame(() => {
      toast.style.opacity = 1;
    });
    setTimeout(() => {
      toast.style.opacity = 0;
      setTimeout(() => toast.remove(), 300);
    }, duration);
  }

  function tryFetchRedirect(link) {
    const hxGetUrl = link.getAttribute('hx-get');
    console.log('[Tampermonkey] Found link:', link);
    console.log('[Tampermonkey] hx-get URL:', hxGetUrl);

    if (!hxGetUrl) {
      showToast('⚠️ Link missing hx-get attribute.', 'error');
      return;
    }

    showToast(' Found link. Fetching redirect…');

    fetch(hxGetUrl, { method: 'GET' })
      .then(response => {
        const redirectUrl = response.headers.get('hx-redirect');
        console.log('[Tampermonkey] Fetch status:', response.status);
        console.log('[Tampermonkey] hx-redirect:', redirectUrl);

        if (redirectUrl) {
          showToast('✅ Redirecting to download…', 'success');
          window.location.href = redirectUrl;
        } else {
          showToast('⚠️ No download redirect found.', 'error');
        }
      })
      .catch(err => {
        console.error('[Tampermonkey] Fetch error:', err);
        showToast('❌ Failed to fetch download link.', 'error');
      });
  }

  function checkForLinkAndFetch() {
    const link = document.querySelector(SELECTOR);
    if (link) {
      console.log('[Tampermonkey] Link found on initial check.');
      showToast(' Download link found.');
      tryFetchRedirect(link);
    } else {
      console.log('[Tampermonkey] No link found. Watching DOM...');
      showToast('⏳ Looking for download link…');
      observeForLink();
    }
  }

  function observeForLink() {
    const observer = new MutationObserver((mutations) => {
      for (const mutation of mutations) {
        for (const node of mutation.addedNodes) {
          if (!(node instanceof HTMLElement)) continue;

          const match = node.matches?.(SELECTOR) ? node : node.querySelector?.(SELECTOR);
          if (match) {
            console.log('[Tampermonkey] Link dynamically detected.');
            observer.disconnect();
            showToast(' Link loaded. Fetching...');
            tryFetchRedirect(match);
            return;
          }
        }
      }
    });

    observer.observe(document.body, {
      childList: true,
      subtree: true,
    });

    console.log('[Tampermonkey] MutationObserver is now active.');
  }

  // Start immediately
  checkForLinkAndFetch();
})();