BuzzCopy

Injects a copy link button next to the download button

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @version     1.0
// @name        BuzzCopy
// @namespace   kyoruno
// @author      kyoruno
// @license     MIT
// @description Injects a copy link button next to the download button
// @icon        https://buzzheavier.com/favicon.ico
// @match       https://buzzheavier.com/*
// @exclude     https://buzzheavier.com/
// @exclude     https://buzzheavier.com/login*
// @exclude     https://buzzheavier.com/pricing*
// @exclude     https://buzzheavier.com/blog*
// @exclude     https://buzzheavier.com/speedtest*
// @exclude     https://buzzheavier.com/whyareyougay*
// @exclude     https://buzzheavier.com/developers*
// @exclude     https://buzzheavier.com/privacy*
// @exclude     https://buzzheavier.com/terms*
// @exclude     https://buzzheavier.com/contact*
// @exclude     https://buzzheavier.com/help*
// @exclude     https://buzzheavier.com/notfound*
// @exclude     https://buzzheavier.com/favicon.ico*
// @grant       none
// @run-at      document-end
// ==/UserScript==

(function() {
  'use strict';

  const log = (...args) => console.log("BuzzCopy:", ...args);

  const buzzUrl = new URL(window.location.href);
  if (!buzzUrl.pathname.endsWith('/download')) {
    buzzUrl.pathname = buzzUrl.pathname.replace(/\/+$/, '') + '/download';
  }

  function createButton() {
    const copyButton = document.createElement('a');
    copyButton.className = 'link-button';
    copyButton.textContent = 'Copy';

    copyButton.addEventListener('click', function(event) {
      event.preventDefault();
      fetch(buzzUrl)
        .then(response => {
          const hxRedirect = response.headers.get("hx-redirect");
          if(!hxRedirect) {
            log("could not retrieve redirect URL");
            alert("BuzzCopy: could not retrieve the link");
            return;
          }
          navigator.clipboard.writeText(hxRedirect)
            .then(() => log(hxRedirect))
            .catch(err => {
              log(err);
              alert("BuzzCopy: failed to use clipboard, check console logs");
            });
        })
        .catch(error => {
          log(error);
        });
    });
    return copyButton;
  }

  function insertButton() {
    const targetButton = document.querySelector('a.gay-button');
    if (!targetButton) {
      log("button not found");
      return;
    }

    const targetLi = targetButton.closest('li');
    if (!targetLi) {
      log("button's parent <li> not found");
      return;
    }

    const button = createButton();
    const space = document.createElement('span');
    space.textContent = ' - ';

    targetLi.insertBefore(button, targetButton);
    targetLi.insertBefore(space, targetButton);
  }

  insertButton();
})();