Skip to content

Instantly share code, notes, and snippets.

@defmech
Last active February 1, 2021 14:54
Show Gist options
  • Save defmech/8fd6d7906c4f99ed36779682aadfe00b to your computer and use it in GitHub Desktop.
Save defmech/8fd6d7906c4f99ed36779682aadfe00b to your computer and use it in GitHub Desktop.
A bookmarklet that copies the current tab's url to the clipboard. Tested in Safari and can be triggered by keyboard shortcut if `Use ⌘-1 to ⌘-9 to switch tabs` is disabled.
javascript: !(function (window, document) {
var tempTextArea = document.createElement("textarea");
const copyText = document.getSelection();
(tempTextArea.textContent = window.location.href),
document.body.appendChild(tempTextArea),
copyText.removeAllRanges(),
tempTextArea.select(),
document.execCommand("copy"),
copyText.removeAllRanges(),
document.body.removeChild(tempTextArea);
})(window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment