Copy Selected Links

Displays a Copy button on selected links.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey, Greasemonkey или Violentmonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Violentmonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Violentmonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Userscripts.

Чтобы установить этот скрипт, сначала вы должны установить расширение браузера, например Tampermonkey.

Чтобы установить этот скрипт, вы должны установить расширение — менеджер скриптов.

(у меня уже есть менеджер скриптов, дайте мне установить скрипт!)

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

(у меня уже есть менеджер стилей, дайте мне установить скрипт!)

// ==UserScript==
// @name        Copy Selected Links
// @namespace   leaumar
// @match       *://*/*
// @grant       GM.setClipboard
// @version     3
// @author      [email protected]
// @description Displays a Copy button on selected links.
// @license     MPL-2.0
// @icon        data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAQAAAD2e2DtAAAjrklEQVR42u2dCXAU15nHNbpvdCB0wQghIQQ6LLPKopW5ZMSRWC6QjEGyEexyOrCIM3a8G4iMU5VNsgvOJlVZO4ezycZsiGM7WZyYxLFSldpNsHGlXIW2lmWzWgqQNHd3z/TM9Bz69ns9o2suzYzm6NeafiWMQaL7ve/3vuO91/9JSkpciSv8CxTSaQlrxO5SJM0Y+MFkiHPDJ5jGgLTEFYM57x78aykggYZPMYlDwh9E1/SDbqMPpULqrTRIG04Hsd3NgDg0vKt4d3yKNHyaVHwqEYZJn5CwWmTnPZlhKcTww2jwkUzI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Dzdq6SFHPHD8AcyagmrJq55XP8PzkY6TjN3rpEAAAAASUVORK5CYII=
// ==/UserScript==

function centerOf(element) {
  const rect = element.getBoundingClientRect();
  return {
    x: rect.left + rect.width / 2,
    y: rect.top + rect.height / 2,
  };
}

const sum = (a, b) => a + b;

function averageOf(offsets) {
  return {
    x: offsets.map(offset => offset.x).reduce(sum) / offsets.length,
    y: offsets.map(offset => offset.y).reduce(sum) / offsets.length,
  };
}

function clamp(value, min, max) {
  return Math.max(min, Math.min(value, max));
}

function toVisibleOffset(center, self) {
  const selfBox = self.getBoundingClientRect();

  const visibleCenter = {
    x: clamp(center.x, selfBox.width / 2, window.innerWidth - selfBox.width / 2),
    y: clamp(center.y, selfBox.height / 2, window.innerHeight - selfBox.height / 2)
  };

  return {
    x: visibleCenter.x - selfBox.width / 2,
    y: visibleCenter.y - selfBox.height / 2,
  };
}

function toCss({ x, y }) {
  return {
    left: `${x}px`,
    top: `${y}px`,
  };
}

// ------------

function makeButton() {
  let toCopy;

  const button = document.createElement('button');
  button.type = 'button';
  Object.assign(button.style, {
    padding: '0.5em',
    position: 'fixed',
    zIndex: 9999,
  });

  // shadow dom stops external css from affecting the button
  const container = document.createElement('div');
  const shadow = container.attachShadow({ mode: 'closed' });
  shadow.appendChild(button);

  function hide() {
    container.remove();
  }

  function attachTo(links) {
    toCopy = links.map(anchor => anchor.href).join('\n');
    button.textContent = `📋${links.length}`;
    document.body.appendChild(container);
    const center = averageOf(links.map(centerOf));
    const offset = toVisibleOffset(center, button);
    Object.assign(button.style, toCss(offset));
  }

  button.addEventListener('mouseup', mouseUp => mouseUp.stopPropagation());
  button.addEventListener('click', click => {
    click.stopPropagation();
    GM.setClipboard(toCopy, "text/plain");
    hide();
  });

  return {
    attachTo,
    hide,
  };
}

(function main() {
  let copyButton;

  document.addEventListener('scroll', () => copyButton?.hide());

  function updateButton() {
    const selection = getSelection();
    if (selection?.type === 'Range') {
      const links = [...document.links].filter(link => selection.containsNode(link, true));
      if (links.length > 0) {
        (copyButton = copyButton ?? makeButton()).attachTo(links);
        return;
      }
    }
    copyButton?.hide();
  }

  // mouseup and click aren't triggered very reliably or consistently -_-
  document.body.addEventListener('mouseup', updateButton);
  document.body.addEventListener('click', updateButton);
})();