Generate a bookmarklet using this tool: https://chriszarate.github.io/bookmarkleter/
Last active
July 29, 2020 18:06
-
-
Save mpontus/96cc1e514ef38e71e4c365ba0a3efcc6 to your computer and use it in GitHub Desktop.
Copy Page Link - bookmarklet to copy a link for the current page in markdown format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
function copy(text) { | |
const node = document.createElement("textarea"); | |
const selection = document.getSelection(); | |
node.textContent = text; | |
document.body.appendChild(node); | |
selection.removeAllRanges(); | |
node.select(); | |
const result = document.execCommand("copy"); | |
selection.removeAllRanges(); | |
document.body.removeChild(node); | |
return result; | |
} | |
function getUrl() { | |
const link = | |
document.querySelector("link[href][rel=shortlink]") || | |
document.querySelector("link[href][rel=canonical]"); | |
if (link !== null) { | |
return link.href; | |
} | |
let url = new URL(window.location.href); | |
url.search = url.search.replace(/(?:^|&)utm_[^&]+/g, "").replace(/^&/, ""); | |
return url.toString(); | |
} | |
let link = `[${document.title}](${getUrl()})`; | |
return copy(link) || alert(link); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment