-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
138 lines (78 loc) · 3.2 KB
/
index.js
File metadata and controls
138 lines (78 loc) · 3.2 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// In renderer process (web page).
const { ipcRenderer } = require('electron')
var loadingText = document.getElementById('loadingText');
var searchGoing = false;
//generate table on page
function generateTable(data){
//delete any previously exisitg table
try {
document.getElementById("allListings").remove()
}
catch(err) {
}
//this code is probably terrible but it works sorry!
var x = document.createElement("TABLE");
x.setAttribute("id", "allListings");
document.body.appendChild(x);
console.log(data.length);
for (index = 0; index < data.length; index += 1){
var y = document.createElement("TR");
y.setAttribute("id", "listingRow" + index);
document.getElementById("allListings").appendChild(y);
console.log(data[index].title);
console.log(data[index].url);
console.log(data[index].price);
console.log(data[index].image_urls);
var titleCell = document.createElement("TD");
titleCell.classList.add("title-cell");
var urlCell = document.createElement("TD");
urlCell.classList.add("url-cell");
urlCell.setAttribute("href", data[index].url);
var priceCell = document.createElement("TD");
priceCell.classList.add("price-cell");
var imageCell = document.createElement("TD");
imageCell.classList.add("image-cell");
var image = document.createElement("IMG");
image.setAttribute("src", data[index].image_urls[0]);
image.setAttribute("class", "listing-image");
var image1 = document.createElement("IMG");
image1.setAttribute("src", data[index].image_urls[1]);
image1.setAttribute("class", "listing-image");
var image2 = document.createElement("IMG");
image2.setAttribute("src", data[index].image_urls[2]);
image2.setAttribute("class", "listing-image");
var titleText = document.createTextNode(data[index].title);
var urlText = document.createTextNode(data[index].url);
var priceText = document.createTextNode(data[index].price);
titleCell.appendChild(titleText);
urlCell.appendChild(urlText);
priceCell.appendChild(priceText);
imageCell.appendChild(image);
imageCell.appendChild(image1);
imageCell.appendChild(image2);
document.getElementById("listingRow" + index).appendChild(titleCell);
document.getElementById("listingRow" + index).appendChild(urlCell);
document.getElementById("listingRow" + index).appendChild(priceCell);
document.getElementById("listingRow" + index).appendChild(imageCell);
}
}
ipcRenderer.on('asynchronous-reply', (event, arg) => {
console.log("recieved listings from backend...");
loadingText.innerHTML = "";
console.log(arg);
generateTable(arg);
searchGoing = false;
})
ipcRenderer.on('systemOutput', (event, arg) => {
console.log(arg);
})
var beginCrawl = document.getElementById('initiate');
beginCrawl.addEventListener('click', (event) => {
if(!searchGoing){
searchGoing = true;
loadingText.innerHTML += "loading... maybe go grab a coffee";
var queryurlfield = document.getElementById("queryurlfield").value;
console.log("button clicked...");
ipcRenderer.send('asynchronous-message', queryurlfield);
}
});