Drag Link to Copy Text

Copy text of any link by simply dragging it.

目前为 2019-04-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Drag Link to Copy Text
  3. // @name:zh 拖动链接以复制文本
  4. // @name:fr Faites glisser le lien pour copier du texte
  5. // @name:de Ziehen Sie den Link zum Kopieren von Text
  6. // @name:ru Перетащите ссылку, чтобы скопировать текст
  7. // @name:es Arrastre el enlace para copiar texto
  8. // @description Copy text of any link by simply dragging it.
  9. // @description:zh 只需拖动即可复制任何链接的文本。
  10. // @description:fr Copiez le texte de n'importe quel lien en le faisant simplement glisser.
  11. // @description:de Kopieren Sie den Text eines Links, indem Sie ihn einfach ziehen.
  12. // @description:ru Скопируйте текст любой ссылки, просто перетащив ее.
  13. // @description:es Copia el texto de cualquier enlace simplemente arrastrándolo.
  14. // @namespace iamMG
  15. // @license MIT
  16. // @version 1.0
  17. // @icon https://i.imgur.com/43qD1oK.png
  18. // @match http*://*/*
  19. // @author iamMG
  20. // @run-at document-end
  21. // @grant GM_setClipboard
  22. // @copyright 2019, iamMG (https://openuserjs.org/users/iamMG)
  23. // ==/UserScript==
  24.  
  25. (function() {
  26. 'use strict';
  27. var links = document.getElementsByTagName("a");
  28. function copier(txt){
  29. return function(){
  30. var temp = document.createElement("textarea");
  31. document.body.appendChild(temp);
  32. temp.innerText = txt;
  33. temp.select();
  34. document.execCommand('copy');
  35. temp.parentElement.removeChild(temp);
  36. }
  37. }
  38. for (var i=0; i<links.length;i++ ){
  39. var txt = links[i].innerText;
  40. if (txt) {links[i].addEventListener('dragend', copier(txt),false);}
  41. }
  42. })();