-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent.js
31 lines (27 loc) · 820 Bytes
/
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
30
31
const el = document.querySelector(".x");
function getSelectedText() {
var text = "";
if (typeof window.getSelection != "undefined") {
text = window.getSelection().toString();
} else if (
typeof document.selection != "undefined" &&
document.selection.type == "Text"
) {
text = document.selection.createRange().text;
}
return text;
}
document.addEventListener("mouseup", (event) => {
var selectedText = getSelectedText();
if (selectedText) {
el.classList.add("active");
el.style.left = event.pageX + "px";
el.style.top = event.pageY + "px";
} else {
el.classList.remove("active");
}
});
const x = document.createElement("div")
x.id = "x"
x.innerHTML = "<img src='assets\icons\48.png'>"
document.body.appendChild(x)