Copy URL Link

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

06.11.2023 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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

(function () {
'use strict';

window.addEventListener('load', () => {
  const evOpts = {
    capture: true,
    passive: true
  };
  let hoveredLink = null;
  function findNearestLink(element) {
    if (!element) {
      return null;
    }
    if (element.tagName === 'A') {
      return element.href;
    }
    return findNearestLink(element.href);
  }
  const linkElements = document.getElementsByTagName('a');
  for (const link of linkElements) {
    link.addEventListener('mouseover', event => {
      hoveredLink = findNearestLink(event.target);
    }, evOpts);
    link.addEventListener('mouseleave', () => {
      hoveredLink = null;
    }, evOpts);
  }
  function eventKeyDown(event) {
    const keyName = event.key;
    if ((event.ctrlKey || event.metaKey) && keyName === 'c') {
      if (hoveredLink !== null) {
        GM.setClipboard(hoveredLink);
      }
    }
  }
  window.addEventListener('keydown', eventKeyDown, evOpts);
});

})();