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-05-29 提交的版本,查看 最新版本

  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.6
  8. // @author snomiao@gmail.com
  9. // @match *://*/*
  10. // @grant none
  11. // ==/UserScript==
  12. // (20200425)更新:优化取标题方案
  13. // (20200425)更新:修改格式
  14. // (20200423)更新:增加格式
  15. (function () {
  16. 'use strict';
  17. var 复制标题文本 = (content) => {
  18. const input = document.createElement('textarea');
  19.  
  20. input.setAttribute('readonly', 'readonly');
  21. input.setAttribute('value', content);
  22. input.innerHTML = (content);
  23. input.setAttribute('style', 'position: fixed; top:0; left:0;z-index: 9999');
  24. document.body.appendChild(input);
  25. input.select();
  26. input.setSelectionRange(0, 9999);
  27.  
  28. let ok = false
  29. if (document.execCommand('copy')) {
  30. document.execCommand('copy');
  31. ok = true
  32. }
  33. document.body.removeChild(input);
  34.  
  35. ok
  36. ? alert(标题地址 + '\n copyied!')
  37. : alert('copy title failed, please check browser version')
  38. return ok || false
  39. };
  40. var 取标题 = () => {
  41. var 标题列 = [...document.querySelectorAll('h1')]
  42. var 页面标题 = 标题列.length == 1 && 标题列[0].innerText.trim() || ''
  43. var 头标题 = document.title || ''
  44. return 页面标题.length > 头标题.length ? 页面标题 : 头标题
  45. }
  46. window.addEventListener('keydown', (e) => {
  47. if (e.altKey && !e.shiftKey && !e.ctrlKey && e.code == 'KeyT')
  48. 复制标题文本(`[${取标题()}]( ${location.href} )`)
  49. if (e.altKey && e.shiftKey && !e.ctrlKey && e.code == 'KeyT')
  50. 复制标题文本(`# ${取标题()}\n${location.href}`)
  51. })
  52. })();

QingJ © 2025

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