-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
59 lines (46 loc) · 1.97 KB
/
options.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var clickedEl = null;
document.addEventListener("contextmenu", function(event){
let currentURL = this.location.href
// console.log(currentURL)
if(currentURL.includes('flipkart')){
clickedEl = event.target.style.backgroundImage.match(/url\(["']?([^"']*)["']?\)/)[1]
//.split(',')[0].slice(4, -1).replace(/"/g, "");
clickedEl = clickedEl.replace("178/178","1160/1160") // the main page preview
clickedEl = clickedEl.replace("248/248","1160/1160") // user images list preview
} else if(currentURL.includes('amazon')){
let elem = event.target;
let classes = elem.classList;
if(classes.contains("cr-lightbox-navigator-container")){
// from the full image, there is none than the following class
clickedEl = document.querySelector(".cr-lightbox-main-image-container img").src;
} else if (classes.contains("cr-thumbnail-preview-tile")){
// from gallery of user images
url = elem.style.background.match(/url\(["']?([^"']*)["']?\)/)[1]
//.split(',')[0].slice(4, -1).replace(/"/g, "");
clickedEl = url.replace("._SY256","") // remove this part to get the full image
} else if(elem.tagName =="IMG"){
// main web page preview
url = elem.src;
// base name
let splitted = url.split("._")
if(splitted.length==2){
let base = splitted[0]
let extn = splitted[1].split('.')[1]
clickedEl = `${base}.${extn}`
}else{
clickedEl = null
}
// regex can be used \._[\w,_]+
} else{
clickedEl = null
}
} else{
clickedEl = null
}
console.log("clicked element ---- ", clickedEl)
}, true);
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if(request == "getClickedEl") {
sendResponse(clickedEl);
}
});