-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpet.js
437 lines (389 loc) · 14.4 KB
/
pet.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
var pet = [
{
img:
"https://img.shop.com/Image/240000/243300/243385/products/559052312.jpg?plain&size=750x750",
name: "Pet Health OPC Formula for Cats & Dogs with Glucosamine",
soldBy: "Sold by Pet Health™",
strikedprice: "80.00",
price: "40.00",
ratio: "+ up to $3.00 / 8% Cashback",
shipping: "Free shipping with $50.00 orders",
category:"petHealth"
},
{
img:
"https://img.shop.com/Image/240000/243300/243385/products/559052317.jpg?plain&size=750x750",
name: "PetHealth™ Multivitamin for Dogs",
soldBy: "Sold by Pet Health™",
strikedprice: "35.00",
price: "15.00",
ratio: "+ $2.40 / 3% Cashback",
shipping: "Free shipping with $40.00 orders",
category:"petHealth"
},
{
img:
"https://img.shop.com/Image/240000/243300/243385/products/1943471621.jpg?plain&size=750x750",
name: "Pet Health CBD Formula for Cats & Dogs Pet Tincture",
soldBy: "Sold by Pet Health™",
strikedprice: "35.00",
price: "30.00",
ratio: "+ up to $1.22 / 2% Cashback",
shipping: "Free shipping with $40.00 orders",
category:"petHealth"
},
{
img:
"https://img.shop.com/Image/240000/243300/243385/products/559052316.jpg?plain&size=750x750",
name: "PetHealth™ Pad & Paw Balm",
soldBy: "Sold by Pet Health™",
strikedprice: "399",
price: "110",
ratio: "+ up to $1.22 / 2% Cashback",
shipping: "Free shipping with $40.00 orders",
category:"petHealth"
},
{
img:
"https://img.shop.com/Image/290000/291700/291715/products/1952389647.jpg?plain&size=400x400",
name: "Nestuo Cat Bed, a Covered Cat Hideaway Hut of Rattan Houses Pets in Dome Basket, Washable",
soldBy: "Sold by Instachew",
strikedprice: "89",
price: "20",
ratio: "+ $0.63 / 3% Cashback",
shipping: "Free shipping with $40.00 orders",
category:"cats"
},
{
img:
"https://img.shop.com/Image/240000/248300/248358/products/1901199675.jpg?plain&size=400x400",
name: "Clearance Center Pet Bed Small ",
soldBy: "Sold by Instachew",
strikedprice: "89",
price: "53",
ratio: "+ $0.63 / 6% Cashback",
shipping: "Free shipping with $40.00 orders",
category:"cats"
},
{
img:
"https://img.shop.com/Image/260000/263300/263383/products/1937741650.jpg?plain&size=400x400",
name: "Aspen Pet 19 In. x 17 In. Oval Polyester Animal Print Cat ",
soldBy: "Sold by Instachew",
strikedprice: "189",
price: "53",
ratio: "+ $0.63 / 3% Cashback",
shipping: "Free shipping with $40.00 orders",
category:"cats"
},
{
img:
"https://img.shop.com/Image/290000/291700/291715/products/1930573294.jpg?plain&size=400x400",
name: "Rockaby Pet Bed",
soldBy: "Sold by Instachew",
strikedprice: "77",
price: "33",
ratio: "+ $0.63 / 3% Cashback",
shipping: "Free shipping with $40.00 orders",
category:"cats"
},
{
img:
"https://img.shop.com/Image/240000/247900/247927/products/1882272867.jpg?plain&size=400x400",
name: "Shopping Annuity Brand Premium Grain-Free Dog Treats",
soldBy: " Sold by Shopping Annuity Necessities",
strikedprice: "177",
price: "39",
ratio: "+ $0.63 / 3% Cashback",
shipping: "Free shipping with $40.00 orders",
category:"dogs"
},
{
img:
"https://img.shop.com/Image/270000/273400/273475/products/1871871527.jpg?plain&size=400x400",
name: "Ultra Chewy 8035569 2.8 oz Peanut Butter Treats for Dogs - Pack of 12",
soldBy: "Sold by AllGourmetFood",
strikedprice: "57",
price: "55",
ratio: "+ $0.63 / 3% Cashback",
shipping: "Free shipping with $40.00 orders",
category:"dogs"
},
{
img:
"https://img.shop.com/Image/270000/273400/273475/products/1848796362.jpg?plain&size=400x400",
name: "Natural Balance 723633775335 8 oz Loving Pets True Venison Jerky Sliders Dog Treats",
soldBy: "Sold by AllGourmetFood",
strikedprice: "57",
price: "27",
ratio: "+ $0.63 / 3% Cashback",
shipping: "Free shipping with $40.00 orders",
category:"dogs"
},
{
img:
"https://img.shop.com/Image/270000/273400/273475/products/1947373704.jpg?plain&size=400x400",
name: "Shameless Pets 00356077 Bacon Dog Treat - Pack of 6",
soldBy: "Sold by AllGourmetFood",
strikedprice: "57",
price: "25",
ratio: "+ $0.63 / 3% Cashback",
shipping: "Free shipping with $40.00 orders",
category:"dogs"
},
{
img:
"https://img.shop.com/Image/240000/248000/248061/products/1885179812.jpg?plain&size=400x400",
name: "45 Brown and Gray Unique Durable Tudor Rabbit Hutch",
soldBy: "Sold by Christmas Central",
strikedprice: "80",
price: "40",
ratio: "+ up to $3.00 / 8% Cashback",
shipping: "Free shipping with $40.00 orders",
category:"animals"
},
{
img:
"https://img.shop.com/Image/250000/251800/251872/products/1946352087.jpg?plain&size=400x400",
name: "Marshall MA00370 Fleece Front Carry Pack for Ferrets",
soldBy: "Sold by UnbeatableSale",
strikedprice: "109",
price: "79",
ratio: "+ $2.40 / 3% Cashback",
shipping: "Free shipping with $40.00 orders",
category:"animals"
},
{
img:
"https://img.shop.com/Image/250000/251800/251872/products/1792959413.jpg?plain&size=400x400",
name: "Carolina Pet 0PP0001-ROC Pendleton Pet National Park Pet Bed - Rocky Mountain, Small",
soldBy: "Sold by UnbeatableSale",
strikedprice: "60",
price: "45",
ratio: "+ up to $1.22 / 2% Cashback",
shipping: "Free shipping with $40.00 orders",
category:"animals"
},
{
img:
"https://img.shop.com/Image/250000/250000/250006/products/1923714140.jpg?plain&size=400x400",
name: "Multi Dura Chew Plus Nyla Multi-Dura Chew Plus Spr",
soldBy: "Sold by UnbeatableSale",
strikedprice: "60",
price: "45",
ratio: "+ up to $1.22 / 2% Cashback",
shipping: "Free shipping with $40.00 orders",
category:"animals"
},
];
displayfun(pet);
displayfun(pet);
document.getElementById("filter").addEventListener("change", changed);
function displayfun(q) {
document.querySelector("#product-container").innerHTML = "";
q.map(function (elem, i) {
var box = document.createElement("div");
var im = document.createElement("img");
im.setAttribute("src", elem.img);
var na = document.createElement("h3");
na.innerText = elem.name;
var sbp = document.createElement("p");
var logo = document.createElement("img");
logo.setAttribute("src", "https://img.shop.com/Image/resources/images/onecart-icon.svg");
// logo.setAttribute("class", "cartlogo");
logo.style.height = "15px"
logo.style.width = "15px";
var sb = document.createElement("span");
sb.innerText = elem.soldBy;
sb.setAttribute("class", "sold");
sbp.append(logo, sb);
sbp.style.marginTop = "-15px";
var pr = document.createElement("p");
var sp1 = document.createElement("span");
sp1.innerText = "$"+elem.strikedprice;
sp1.style.fontSize = ".75rem";
sp1.style.textDecoration = "line-through";
var sp2 = document.createElement("span");
sp2.innerText = "$"+elem.price;
sp2.setAttribute("class", "oprice");
pr.append(sp1, sp2);
pr.style.marginTop = "-6px";
var cbp = document.createElement("p");
var rato = document.createElement("span");
rato.innerText = elem.ratio;
rato.style.marginRight = "5px";
var logo2 = document.createElement("img");
logo2.setAttribute("src", "https://img.shop.com/Image/resources/images/cashback-icon.svg");
//logo2.setAttribute("class", "dollar");
logo2.style.height = "13px";
logo2.style.width = "13px";
var cb = document.createElement("span");
cb.innerText = "Cashback";
cbp.append(rato, logo2, cb);
cbp.style.fontSize = ".75rem";
cbp.style.marginTop = "-8px";
var sp = document.createElement("span");
sp.innerText = elem.shipping;
sp.style.color = "#007e97";
sp.style.fontSize = ".75rem";
sp.style.marginBottom = "15px";
var bdiv = document.createElement("div");
bdiv.setAttribute("class", "buttons")
var sd = document.createElement("div");
var anchor=document.createElement("a");
anchor.innerText="See Details";
sd.append(anchor);
anchor.setAttribute("href","details.html");
anchor.setAttribute("class","anch");
anchor.addEventListener("click",function(){
det(elem);
});
//sd.setAttribute("class", "details");
var atc = document.createElement("button");
atc.innerText = "Add to Cart";
atc.addEventListener("click", function () {
cart(elem, i);
});
// atc.setAttribute("class", "addtocart");
bdiv.append(sd, atc)
box.append(im, na, sbp, pr, cbp, sp, bdiv);
document.getElementById("product-container").append(box);
});
}
function det(elem){
var arr=[];
arr.push(elem);
localStorage.setItem("detail",JSON.stringify(arr));
//location.replace("details.html");
}
var cartArr = JSON.parse(localStorage.getItem("cart-list")) || [];
var count = localStorage.getItem("cartcount") || 0;
document.querySelector(".cart-count").innerText = count;
function cart(elem, i) {
cartArr.push(elem);
count++;
document.querySelector(".cart-count").innerText = count;
localStorage.setItem("cart-list", JSON.stringify(cartArr));
localStorage.setItem("cartcount", count);
}
function changed() {
var catt = document.querySelector("#filter").value;
if (catt == "") {
displayfun(pet);
} else {
var p = pet.filter(function (item) {
if (item.category == catt) {
return item;
}
});
displayfun(p);
}
}
document.querySelector("#filtergame").addEventListener("click", filterfun1);
document.querySelector("#filterhome").addEventListener("click", filterfun2);
document.querySelector("#filterapparel").addEventListener("click", filterfun3);
document.querySelector("#filterfootball").addEventListener("click", filterfun4);
function filterfun1() {
let q =pet.filter(function (item) {
if (item.category == "petHealth") {
return item;
}
});
displayfun(q);
}
function filterfun2() {
let q = pet.filter(function (item) {
if (item.category == "cats") {
return item;
}
});
displayfun(q);
}
function filterfun3() {
let q = pet.filter(function (item) {
if (item.category == "dogs") {
return item;
}
});
displayfun(q);
}
function filterfun4() {
let q = pet.filter(function (item) {
if (item.category == "animals") {
return item;
}
});
displayfun(q);
}
/* <!-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= --> */
function onClickMenu() {
document.getElementById("menu").classList.toggle("icon");
document.getElementById("nav").classList.toggle("change");
}
/* <!-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= --> */
document.querySelector(".logo").addEventListener("click",function(){
window.open("project.html");
});
// search functionality
document.querySelector(".btn1").addEventListener("click",funsearch);
function funsearch(){
event.preventDefault();
var key=document.querySelector("#search").value;
key=key.toUpperCase();
if(key.includes("BEAUTY")){
window.open("beauty.html","_self");
document.querySelector("#search").value="";
}else if(key.includes("CLOTH")){
window.open("clothe.html","_self");
document.querySelector("#search").value="";
}else if(key.includes("FOOD")){
window.open("food.html","_self");
document.querySelector("#search").value="";
}else if(key.includes("HEALTH")){
window.open("health.html","_self");
document.querySelector("#search").value="";
}else if(key.includes("HOME")){
window.open("home.html","_self");
document.querySelector("#search").value="";
}else if(key.includes("JWELLERY")){
window.open("jwellery.html","_self");
document.querySelector("#search").value="";
}else if(key.includes("KIDS")){
window.open("kids.html","_self");
document.querySelector("#search").value="";
}else if(key.includes("PET")){
window.open("pet.html","_self");
document.querySelector("#search").value="";
}else if(key.includes("SHOES")){
window.open("shoes.html","_self");
document.querySelector("#search").value="";
}
else if (key.includes("ELECTRONICS")) {
window.open("electronic.html", "_self");
document.querySelector("#search").value = "";
}else if(key.includes("SPORTS")){
window.open("sports.html","_self");
document.querySelector("#search").value="";
}else{
alert("item not found");
}
}
//feedback
document.getElementById("submitfeedback").addEventListener("click",function(){
let val=document.getElementById("feedbacktext").value;
if(val.length>0){
alert("Thank you for your valuable feedback!!!");
}
});
//username
document.querySelector("#user-name").textContent=JSON.parse(localStorage.getItem("userName"))||"Sign In"
// microphone
const button = document.querySelector('#mic');
const textInput = document.querySelector('#search');
button.addEventListener('click', () => {
const recognition = new webkitSpeechRecognition();
recognition.onresult = event => {
textInput.value = event.results[0][0].transcript;
};
recognition.start();
});