Skip to content

Instantly share code, notes, and snippets.

@jrdmb
Last active October 21, 2024 21:31
Show Gist options
  • Save jrdmb/2eda28b6ab716889646a8d931442af52 to your computer and use it in GitHub Desktop.
Save jrdmb/2eda28b6ab716889646a8d931442af52 to your computer and use it in GitHub Desktop.
JavaScript browser bookmarklets: copy url to clipboard in markdown and html format
Copy URL in Markdown format:
javascript:(function() {text='[' + document.title + '](' + location.href+')' + window.getSelection(); navigator.clipboard.writeText(text);tempAlert("<mark><b>URL COPIED TO CLIPBOARD</mark></b>", 2000); function tempAlert(msg, duration) {var el = document.createElement("div"); el.setAttribute("style","position:absolute;top:5%;left:20%;background-color:white;"); el.innerHTML = msg; document.body.appendChild(el); setTimeout(function(){el.parentNode.removeChild(el);}, duration);}})();
Copy URL in HTML format:
javascript:(function() {text='<a href="'+location.href + '">' + document.title +'</a><br>' + window.getSelection(); navigator.clipboard.writeText(text);tempAlert("<mark><b>URL COPIED TO CLIPBOARD</mark></b>", 2000); function tempAlert(msg, duration) {var el = document.createElement("div"); el.setAttribute("style","position:absolute;top:5%;left:20%;background-color:white;"); el.innerHTML = msg; document.body.appendChild(el); setTimeout(function(){el.parentNode.removeChild(el);}, duration);}})();
These also copy any selected text to the clipboard along with the url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment