Drag Link to Copy Text

Copy text of any link by simply dragging it.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         	Drag Link to Copy Text
// @name:zh			拖动链接以复制文本
// @name:fr			Faites glisser le lien pour copier du texte
// @name:de			Ziehen Sie den Link zum Kopieren von Text
// @name:ru			Перетащите ссылку, чтобы скопировать текст
// @name:es			Arrastre el enlace para copiar texto
// @description  	Copy text of any link by simply dragging it.
// @description:zh	只需拖动即可复制任何链接的文本。
// @description:fr	Copiez le texte de n'importe quel lien en le faisant simplement glisser.
// @description:de	Kopieren Sie den Text eines Links, indem Sie ihn einfach ziehen.
// @description:ru	Скопируйте текст любой ссылки, просто перетащив ее.
// @description:es	Copia el texto de cualquier enlace simplemente arrastrándolo.
// @namespace    	iamMG
// @license			MIT
// @version     	1.1
// @icon			https://i.imgur.com/43qD1oK.png
// @match        	http*://*/*
// @author       	iamMG
// @run-at			document-end
// @grant        	GM_setClipboard
// @copyright		2020, iamMG (https://openuserjs.org/users/iamMG)
// ==/UserScript==

(function() {
    'use strict';
	var links = document.getElementsByTagName("a");
	function copier(txt) {
		return function() {
			var temp = document.createElement("textarea");
			document.body.appendChild(temp);
			temp.innerText = txt;
			temp.select();
			if (document.visibilityState == 'visible') document.execCommand('copy');
			temp.parentElement.removeChild(temp);
		}
	}
	for (var i=0; i<links.length; i++ ) {
		var txt = links[i].innerText;
		if (txt) {links[i].addEventListener('dragend', copier(txt), false);}
	}
})();