Copy Title Alt+T

Press Alt+T to copy title and url like this `# ${TITLE}\n${URL}` and Alt+Shift+T to copy the markdown style link `[${TITLE}]( ${URL} )`

当前为 2020-04-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Copy Title Alt+T
  3. // @name:zh Alt+T 复制标题和地址快速分享
  4. // @description Press Alt+T to copy title and url like this `# ${TITLE}\n${URL}` and Alt+Shift+T to copy the markdown style link `[${TITLE}]( ${URL} )`
  5. // @description:zh 按 Alt+T 复制 Markdown 格式的链接 `[${TITLE}]( ${URL} )` and Alt+Shift+T 复制 标题和地址 `# ${TITLE}\n${URL}`
  6. // @namespace https://userscript.snomiao.com/
  7. // @version 0.5
  8. // @author snomiao@gmail.com
  9. // @match *://*/*
  10. // @grant none
  11. // ==/UserScript==
  12. // (20200425)更新:修改格式
  13. // (20200423)更新:增加格式
  14. (function () {
  15. 'use strict';
  16. var 复制标题文本 = (content) => {
  17. const input = document.createElement('textarea');
  18.  
  19. input.setAttribute('readonly', 'readonly');
  20. input.setAttribute('value', content);
  21. input.innerHTML = (content);
  22. input.setAttribute('style', 'position: fixed; top:0; left:0;z-index: 9999');
  23. document.body.appendChild(input);
  24. input.select();
  25. input.setSelectionRange(0, 9999);
  26.  
  27. let ok = false
  28. if (document.execCommand('copy')) {
  29. document.execCommand('copy');
  30. ok = true
  31. }
  32. document.body.removeChild(input);
  33.  
  34. ok
  35. ? alert(标题地址 + '\n copyied!')
  36. : alert('copy title failed, please check browser version')
  37. return ok || false
  38. };
  39. var 取标题 = () => {
  40. var 标题列 = [...document.querySelectorAll('h1')]
  41. return 标题列.length == 1 && 标题列[0].innerText.trim() || document.title || ''
  42. }
  43. window.addEventListener('keydown', (e) => {
  44. if (e.altKey && !e.shiftKey && !e.ctrlKey && e.code == 'KeyT')
  45. 复制标题文本(`[${取标题()}]( ${location.href} )`)
  46. if (e.altKey && e.shiftKey && !e.ctrlKey && e.code == 'KeyT')
  47. 复制标题文本(`# ${取标题()}\n${location.href}`)
  48. })
  49. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址