BuzzCopy

Injects a copy link button next to the download button

当前为 2025-05-09 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 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();
})();