-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
116 lines (95 loc) · 3.69 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
chrome.runtime.onMessage.addListener(shuntasi);
function shuntasi(kipathaise, sender, sendresponse ){
if( kipathaise.save === "savetitles"){
var formData = new FormData();
let cnt = 1;
let url = document.URL + "";
url = url.split('#')[0];
document.querySelectorAll("h3").forEach(ink => {
let x = ink.querySelector("a");
let pre = "https://amzn";
let st = x + "";
if(x != null && st.startsWith(pre) ){
//console.log( " "+ x.innerHTML + " " + x);
formData.append( 'id', cnt );
formData.append( 'product_name', x.innerHTML+"" );
formData.append( 'product_link', st );
formData.append( 'page_link', url+"" );
//sendMyAss(formData);
// sendresponse({product_name: x.innerHTML+"", product_link: st , page_link: url+""});
chrome.runtime.sendMessage({'send':'sendtoserver',product_name: x.innerHTML+"", product_link: st , page_link: url+""});
}
});
document.querySelectorAll("h2").forEach(ink => {
let x = ink.querySelector("a");
let pre = "https://amzn";
let st = x + "";
if(x != null && st.startsWith(pre) ){
//console.log( " "+ x.innerHTML + " " + x);
formData.append( 'id', cnt );
formData.append( 'product_name', x.innerHTML+"" );
formData.append( 'product_link', st );
formData.append( 'page_link', url+"" );
//sendMyAss(formData);
//sendresponse({product_name: x.innerHTML+"", product_link: st , page_link: url+""});
chrome.runtime.sendMessage({'send':'sendtoserver',product_name: x.innerHTML+"", product_link: st , page_link: url+""});
}
});
document.querySelectorAll("h4").forEach(ink => {
let x = ink.querySelector("a");
let pre = "https://amzn";
let st = x + "";
if(x != null && st.startsWith(pre) ){
// console.log( " "+ x.innerHTML + " " + x);
formData.append( 'id', cnt );
formData.append( 'product_name', x.innerHTML+"" );
formData.append( 'product_link', st );
formData.append( 'page_link', url+"" );
//sendMyAsset(formData);
//sendresponse({product_name: x.innerHTML+"", product_link: st , page_link: url+""});
chrome.runtime.sendMessage({'send':'sendtoserver',product_name: x.innerHTML+"", product_link: st , page_link: url+""});
}
});
alert("All Data saved");
}
// else if (kipathaise.from === "getinfo") {
// // getMyAsset(kipathaise.url);
// sendresponse({farewell: "Showed"});
// }
}
// function addModal() {
// alert("fuck");
// $("body").append('<div class="modal fade" id="myModal" role="dialog"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal">×</button><h4 class="modal-title">Modal Header</h4></div><div class="modal-body"><p>Some text in the modal.</p></div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div</div></div></div>');
// }
function getMyAsset(urls){
urls = urls+"";
// console.log(urls);
$.ajax({
url: urls,
type: 'GET',
success: function(obj){
alert(obj["Product"] + "\n" + obj["Page"] );
// addModal();
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}
function sendMyAsset(formData){
$.ajax({
type: 'POST',
url: 'http://localhost/db1/script.php',
data: formData,
processData: false,
contentType: false,
dataType:'jsonp',
success: function(gotIt,status){
console.log("Data Saved Successfully to the Model");
},
error : function(){
console.log('Something is Wrong with the server');
}
})
}