Skip to content

Instantly share code, notes, and snippets.

@andfinally
Last active July 11, 2022 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andfinally/453d93543815587991378222c20c10fa to your computer and use it in GitHub Desktop.
Save andfinally/453d93543815587991378222c20c10fa to your computer and use it in GitHub Desktop.
Bookmarklet to copy document title and URL
// One-line version: create a bookmark with this content
// javascript:( function() { const jsIssueTitle = document.querySelector( '.js-issue-title' ); const title = jsIssueTitle ? jsIssueTitle.textContent : document.title; const blob = new Blob( [ `<a href="${ document.location.href }">${ title }</a>` ], { type: "text/html" } ); const clipboardItem = new ClipboardItem( { [ "text/html" ]: blob } ); navigator.clipboard.write( [ clipboardItem ] ); } )();
// Long version - only included here for legibility use the one-line version prefixed with `javascript:`
( function() {
// Get GitHub issue/PR title
const jsIssueTitle = document.querySelector( '.js-issue-title' );
const title = jsIssueTitle ? jsIssueTitle.textContent : document.title;
const blob = new Blob( [ `<a href="${ document.location.href }">${ title }</a>` ], { type: "text/html" } );
const clipboardItem = new ClipboardItem( { [ "text/html" ]: blob } );
navigator.clipboard.write( [ clipboardItem ] );
} )();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment