答案1
您可以使用 tampermonkey chrome 扩展来执行此操作,
脚本如下:
// ==UserScript==
// @name ctrl + mouse-right-click to copy title from cloest element
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://*/*
// @grant GM_setClipboard
// ==/UserScript==
;
(function() {
'use strict';
let clickFn=(ev)=>{
console.log(`begin copy title from cloest element ...`)
if(ev.ctrlKey){
ev.preventDefault()
}else{
console.log(` please hold down the Ctrl key`)
return
}
let target=ev.target
let v=""
if(1){
let pp=target
let bb=document.body
let distance=-1
let attr='title'
// attr='id'
while(pp!==bb){
distance++
if(pp.hasAttribute(attr)){
v=pp.getAttribute(attr)
console.log(`dis:${distance}|tag:${pp.tagName}|title:${v}`)
GM_setClipboard(v,"text")
break
}
pp=pp.parentElement
}
}
if(v){
console.log(`copy title success`)
}else{
console.log(`title Not found`)
}
}
//document.addEventListener("click",clickFn)
document.addEventListener("contextmenu",clickFn)
})();
用法:
按住 ctrl 键,然后按鼠标右键