Hover the cursor over a link and trigger, to copy a Markdown version of the link.
Copy webpage link under cursor as Markdown.kmmacros (24.9 KB)
Main script:
(function () {
// MOUSE HOVERING OVER A NODE ?
var nh = document.querySelectorAll(':hover'),
iLast = (nh ? nh.length : null),
nodeHover = (iLast ? nh[iLast - 1] : null),
// LINK IN ANY NODE UNDER MOUSE ?
oLinkNode = nodeHover ? document.evaluate(
document.kmvar.xPath,
nodeHover,
null, XPathResult.FIRST_ORDERED_NODE_TYPE, 0
).singleNodeValue : null;
// MARKDOWN LINK ?
return oLinkNode ? (
'[' + oLinkNode.text + '](' +
(oLinkNode.getAttribute('data-href') ||
oLinkNode.href) + ')'
) : ''
})();