var x = null;
var y = null;
document.addEventListener('mousemove', onMouseUpdate, false);
document.addEventListener('mouseenter', onMouseUpdate, false);
function onMouseUpdate(e) {
x = e.clientX;
y = e.clientY;
}
function contains(x,y, rect){
return rect.left <= x && x <= rect.right && rect.top <= y && y <= rect.bottom;
}
hotkeys('ctrl+d',function(event){
for(let link of Array.prototype.slice.call(document.getElementsByTagName('a')) ){
if(contains(x, y, link.getBoundingClientRect())){
event.preventDefault();
event.stopImmediatePropagation();
if(link.href){
console.log(link.href);
navigator.clipboard.writeText(link.href);
}
break;
}
}
})
https://jsfiddle.net/QW01_01/j3ydxp28/26/
Использованы библиотеки
https://github.com/lgarron/clipboard-polyfill
https://github.com/jaywcjlove/hotkeys