BuzzCopy

Injects a copy link button next to the download button

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();
})();