-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
33 lines (29 loc) · 851 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
32
33
document.addEventListener("contextmenu", function(e){
if(e.target.tagName === "IMG"){
message = e.target.src;
}
else{
var img = e.target;
var style = img.currentStyle || window.getComputedStyle(img, false);
var url = style.backgroundImage.slice(4, -1);
console.log(url);
if((/\.(gif|jpg|jpeg|tiff|tif|png|bmp|webp)/).test(url)){
message = url.slice(1, -1);
}
else if(url === ""){
message = null;
}
else{
message = "unsupported";
}
}
browser.runtime.sendMessage(message);
});
browser.runtime.onMessage.addListener(function(message){
if(message === "unsupported"){
alert("This type of image is not supported");
}
else{
alert("No image selected!");
}
});