-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
77 lines (71 loc) · 2.1 KB
/
index.js
File metadata and controls
77 lines (71 loc) · 2.1 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
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
const fetch = require("node-fetch");
const cheerio = require("cheerio");
const btnEl = document.getElementById("btn-el");
const inputEl = document.getElementById("input-el");
const ulEl = document.getElementById("ul-el");
let sites = [];
const url = ''
//getting the sites info from the local storage
let sfls = JSON.parse(localStorage.getItem("sites"));
if (sfls) {
sites = sfls;
render(sites);
}
// const tabs=[
// {url:"www.flipkart.com"}
// ]
btnEl.addEventListener("click", function () {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
sites.push(tabs[0].url);
inputEl.value = "";
localStorage.setItem("sites", JSON.stringify(sites));
render(sites);
});
});
function render(sites) {
let listitem = "";
console.log(sites);
for (let i = 0; i < sites.length; i++) {
listitem += `
<li>
<a target='_blank' href='${sites[i]}'>
${sites[i]}
</a>
</li>`;
}
ulEl.innerHTML = listitem;
}
const getFlipkartData = async (url) => {
var requestOptions = {
method: "GET",
headers: {
Cookie:
"SN=VI433AE878EB73468CB6C921F9FE2C820B.TOK4280C5FE4DED487C8ECFEA75779307BC.1647169991.LO; T=TI164716999139500296827170616890881757764964967280888178739446404112",
},
redirect: "follow",
};
const res = await fetch(url, requestOptions);
const body = await res.text();
const $ = cheerio.load(body);
const img = $("._3exPp9");
const title = img.attr("alt");
const imageData = img.attr("src");
return [title, imageData];
};
const getAmazonData = async (url) => {
var requestOptions = {
method: "GET",
headers: {
Cookie:
"SN=VI433AE878EB73468CB6C921F9FE2C820B.TOK4280C5FE4DED487C8ECFEA75779307BC.1647169991.LO; T=TI164716999139500296827170616890881757764964967280888178739446404112",
},
redirect: "follow",
};
const res = await fetch(url, requestOptions);
const body = await res.text();
const $ = cheerio.load(body);
const img = $(".a-dynamic-image");
const title = img.attr("alt");
const imageData = img.attr("src");
return [title, imageData];
};