惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

小众软件
小众软件
MyScale Blog
MyScale Blog
N
News and Events Feed by Topic
IT之家
IT之家
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
The Cloudflare Blog
博客园 - 聂微东
Apple Machine Learning Research
Apple Machine Learning Research
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
美团技术团队
V
Visual Studio Blog
M
MIT News - Artificial intelligence
V
V2EX
博客园_首页
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Blog — PlanetScale
Blog — PlanetScale
F
Full Disclosure
H
Help Net Security
MongoDB | Blog
MongoDB | Blog
博客园 - 叶小钗
S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
D
Docker
Engineering at Meta
Engineering at Meta
博客园 - Franky
aimingoo的专栏
aimingoo的专栏
Jina AI
Jina AI
N
Netflix TechBlog - Medium
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
I
InfoQ
G
Google Developers Blog
L
LangChain Blog
F
Fortinet All Blogs
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
WordPress大学
WordPress大学
A
Arctic Wolf
Martin Fowler
Martin Fowler
G
GRAHAM CLULEY
L
LINUX DO - 热门话题
C
Cisco Blogs
Y
Y Combinator Blog
罗磊的独立博客

Darek Kay

Sabbatical #18: Great Ocean Road Sabbatical #17: Melbourne Sabbatical #16: Kaikōura Sabbatical #15: Tasman-Marlborough Sabbatical #14: West Coast Sabbatical #13: Wānaka Sabbatical #12: Milford Sound Sabbatical #11: Queenstown Sabbatical #10: Mackenzie Basin Sabbatical #09: Dunedin Sabbatical #08: Christchurch Sabbatical #07: Waitomo Sabbatical #06: Tongariro National Park Sabbatical #05: Rotorua Lakes Sabbatical #04: Coromandel Peninsula Sabbatical #03: Auckland Sabbatical #02: Doha Sabbatical #01: Getting ready Open Graph images: Format compatibility across platforms
Grab browser links and titles in one click
Darek Kay · 2025-01-03 · via Darek Kay

When I copy a browser tab URL, I often want to also keep the title. Sometimes I want to use the link as rich text (e.g., when pasting the link into OneNote or Jira). Sometimes I prefer a Markdown link. There are browser extensions to achieve this task, but I don't want to introduce potential security issues. Instead, I've written a bookmarklet based on this example extension.

To use it, drag the following link onto your browser bookmarks bar:

Copy Tab

When you click the bookmark(let), the current page including its title will be copied into your clipboard. You don't even have to choose the output format: the link is copied both as rich text and plain text (Markdown). This works because it's possible to write multiple values into the clipboard with different content types.

Here's the source code:

function escapeHTML(str) {
  return String(str)
    .replace(/&/g, "&")
    .replace(/"/g, """)
    .replace(/'/g, "'")
    .replace(/</g, "&lt;")
    .replace(/>/g, "&gt;");
}

function copyToClipboard({ url, title }) {
  function onCopy(event) {
    document.removeEventListener("copy", onCopy, true);
    // hide the event from the page to prevent tampering
    event.stopImmediatePropagation();
    event.preventDefault();

    const linkAsMarkdown = `[${title}](${url})`;
    event.clipboardData.setData("text/plain", linkAsMarkdown);

    const linkAsHtml = `<a href="${escapeHTML(url)}">${title}</a>`;
    event.clipboardData.setData("text/html", linkAsHtml);
  }
  document.addEventListener("copy", onCopy, true);
  document.execCommand("copy");
}

copyToClipboard({ url: window.location.toString(), title: document.title });