-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
86 lines (67 loc) · 2.59 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
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
/* If the received message has the expected format... */
if (msg.text && (msg.text == "report_back")) {
//INIT
var dimensions = "null";
var itemNum = "null";
var boxWeight = "null";
var details;
//Scrap details from amazon website
if(document.getElementById('detail_bullets_id')) {
details = document.getElementById('detail_bullets_id') ;
details = details.getElementsByTagName('ul')[0];
try {
details = details.getElementsByTagName('li');
for (var i = 0; i < details.length; i++) {
if ( details[i].getElementsByTagName('b')[0].innerHTML.match(/Product Dimensions/g))
{
var pos = details[i].innerHTML.search("</b>");
dimensions = details[i].innerHTML.substring(pos+4,details[i].innerHTML.length);
}
if ( details[i].getElementsByTagName('b')[0].innerHTML.match(/Item model number/g))
{
pos = details[i].innerHTML.search("</b>");
itemNum = details[i].innerHTML.substring(pos+4,details[i].innerHTML.length);
}
if ( details[i].getElementsByTagName('b')[0].innerHTML.match(/Boxed-product Weight/g))
{
pos = details[i].innerHTML.search("</b>");
boxWeight = details[i].innerHTML.substring(pos+4,details[i].innerHTML.length);
}
};
}
catch(err){
details = err ;
}
}
else if((document.getElementById('prodDetails')))
{
details = document.getElementById('prodDetails') ;
details = details.getElementsByTagName('table');
det = details[0].getElementsByTagName('td');
for ( var j = 0 ; j< det.length ;j++)
{
console.log(det[j].innerHTML+" ");
if (det[j].innerHTML == "Model Number"){
{
itemNum = det[j+1].innerHTML;
}
}
if (det[j].innerHTML == "Item Weight"){
{
boxWeight = det[j+1].innerHTML;
}
}
if (det[j].innerHTML == "Product Dimensions"){
{
dimensions = det[j+1].innerHTML;
}
}
}
}
//construct object to send
var prod = {title:document.getElementById('productTitle').innerHTML, by:document.getElementById('brand').innerHTML,
ASIN:document.getElementById('ASIN').value, dim:dimensions , num:itemNum , weight:boxWeight ,url : document.URL, tab : msg.tab};
sendResponse(prod);
}
});