copy title

shift+c to copy title link

目前为 2020-12-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name copy title
  3. // @description shift+c to copy title link
  4. // @name:en copy title
  5. // @description:en shift+c to copy title link
  6. // @name:ko 페이지 제목 복사
  7. // @description:ko shift+c로 페이지 제목 링크 복사
  8. // @namespace https://greasyfork.org/ko/users/713014-nanikit
  9. // @version 201218
  10. // @author nanikit
  11. // @match *://*/*
  12. // @grant none
  13. // ==/UserScript==
  14. 'use strict';
  15.  
  16. const copyTitleHandler = (event) => {
  17. const titleText = document.title;
  18. const anchor = document.createElement('a');
  19. anchor.href = document.location.href;
  20. anchor.innerText = titleText;
  21. const titleHtml = anchor.outerHTML;
  22. event.clipboardData.setData("text/html", titleHtml);
  23. event.clipboardData.setData("text/plain", titleText);
  24. event.preventDefault();
  25. }
  26.  
  27. const copyTitle = () => {
  28. document.addEventListener("copy", copyTitleHandler);
  29. document.execCommand("copy");
  30. document.removeEventListener("copy", copyTitleHandler);
  31. };
  32.  
  33. window.addEventListener('keydown', (event) => {
  34. if (event.shiftKey && event.key === 'C') {
  35. copyTitle();
  36. }
  37. });