Copy URL Link

一個用來複製連結網址的userscript

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Copy URL Link
// @namespace   https://github.com/nickburrows/userscript-copy-link
// @description 一個用來複製連結網址的userscript
// @match       *://*/*
// @inject-into content
// @version     0.0.44
// @author      Nick Lin
// @icon        https://raw.githubusercontent.com/nickburrows/userscript-copy-link/e8f248af59bea72aeb08ded7743765ac1d6801ef/static/icon_32.png
// @grant       GM.setClipboard
// @grant       GM_setClipboard
// ==/UserScript==

(function () {
'use strict';

window.addEventListener('load', () => {
  const evOpts = {
    capture: true,
    passive: true
  };
  let hoveredLink = null;
  const linkElements = document.getElementsByTagName('a');
  for (const link of linkElements) {
    link.addEventListener('mouseenter', () => {
      hoveredLink = link;
    }, evOpts);
    link.addEventListener('mouseleave', () => {
      hoveredLink = null;
    }, evOpts);
  }
  function eventKeyDown(ev) {
    if (hoveredLink && (ev.metaKey || ev.ctrlKey) && ev.key === 'c') {
      const linkUrl = hoveredLink.href;
      if (linkUrl !== null) {
        GM_setClipboard(linkUrl);
      }
    }
  }
  window.addEventListener('keydown', eventKeyDown, evOpts);
});

})();