-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
38 lines (37 loc) · 1.08 KB
/
content.js
File metadata and controls
38 lines (37 loc) · 1.08 KB
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
32
33
34
35
36
37
38
const shortTextForNumber = (number) => {
if (number < 10000) {
return number.toString()
} else if (number < 1000000) {
return Math.floor(number / 1000)
.toString() + "k"
} else {
return Math.floor(number / 1000 / 1000)
.toString() + "m"
}
}
let div = document.createElement('div');
div.className = "rankrank0";
document.body.append(div);
let myhostname = null;
document.addEventListener("mouseover", (e) => {
//console.log(e.target.closest('a'));
let a = e.target.closest('a');
if (a === null) return;
let hostname = new URL(e.target.closest('a').href).hostname;
if (hostname === '') return;
myhostname = hostname;
chrome.runtime.sendMessage({
"hostname": hostname
},
(msg) => {
if (msg.hostname !== myhostname) return;
let rank = msg.rank;
if (typeof rank === 'number') rank = shortTextForNumber(rank);
div.innerHTML = 'S ' + rank;
}
)
});
document.addEventListener("mouseout", () => {
div.innerHTML = "";
myhostname = null;
});