-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
33 lines (27 loc) · 1.01 KB
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// content.js
browser.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.action === "copyInnerText") {
var element = document.getElementById(request.element);
var text = element.innerText;
navigator.clipboard.writeText(text).then(function() {
//console.log("Text copied to clipboard: " + text);
});
}
});
document.addEventListener("contextmenu", function(event) {
var target = event.target;
target.setAttribute("id", "context-menu-target");
});
// Listen for right-click events
document.addEventListener("mousedown", event => {
if (event.button === 2) {
// Get the right-clicked element
const element = document.elementFromPoint(event.clientX, event.clientY);
let targetInnerText = element.innerText || ((event && event.target)? event.target.innerText : "");
// Send a message to the background script with the inner text of the element
browser.runtime.sendMessage({
type: "copy-inner-text",
innerText: targetInnerText
});
}
});