-
Notifications
You must be signed in to change notification settings - Fork 1
/
skin.js
241 lines (206 loc) · 9.19 KB
/
skin.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
let skinData = [
{imageUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/NicoLips-01_77788ac8-4061-459a-bfb5-f5b5068c1dfa_700x.jpg?v=1652340499",
name: "NICOLIP LIP BRIGHTENING SCRUB, 20GM",
description: "Lip Brightening, Nousrishing & Repairing",
price: "315",
stackedPrice: "₹ 450",
rating: "4.7 ★",
productID: "S-01",
hoverUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/NicoLips-02_360x.jpg?v=1652340499"},
{imageUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/EyeLift-01_4ac1ff22-cbb1-4b18-8b9e-11204b255113_700x.jpg?v=1652340587",
name: "EYELIFT UNDER EYE CREAM, 20GM",
description: "Repairs Dark Circles, Puffy Eyes & Wrinkles",
price: "228",
stackedPrice: "₹ 325",
rating: "4.7 ★",
productID: "S-02",
hoverUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/Eyelift-02_360x.jpg?v=1652340587"},
{imageUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/C-GlowFaceWash-01_2_700x.jpg?v=1652340405",
name: "C-GLOW FACE WASH, 100ML",
description: "De-Tan & Brightening",
price: "174",
stackedPrice: "₹ 249",
rating: "4.7 ★",
productID: "S-03",
hoverUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/C-GlowFaceWash-02_360x.jpg?v=1652340405"},
{imageUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/Kumkumadi-Face-Oil-01_700x.jpg?v=1652341175",
name: "AYURVEDIC KUMKUMADI FACE OIL, 30ml",
description: "Skin Brightening & Hydrating Oil For Youthful Skin",
price: "419",
stackedPrice: "₹ 599",
rating: "4.7 ★",
productID: "S-04",
hoverUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/KumkumadiFaceOil-02_360x.jpg?v=1652341175"},
{imageUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/Anti-AcneFaceGel-01_0b665e08-c71f-409a-82ef-10b68c67e453_700x.jpg?v=1651699935",
name: "ANTI ACNE, PIMPLE SCAR SPOTS REMOVAL GEL FOR MEN & WOMEN, 50gm",
description: "Pimple Scar Removal & Skin Clarifying",
price: "279",
stackedPrice: "₹ 399",
rating: "4.7 ★",
productID: "S-05",
hoverUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/Anti-AcneFaceGel-02_1_360x.jpg?v=1652075347"},
{imageUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/KumkumadiFaceWash-01_1_700x.jpg?v=1652341314",
name: "KUMKUMADI FACE WASH - 100ml",
description: "Pore Cleansing, Radiating & Skin Rejuvenating",
price: "279",
stackedPrice: "₹ 399",
rating: "4.7 ★",
productID: "S-06",
hoverUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/KumkumadiFaceWash-02_360x.jpg?v=1652341314"},
{imageUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/NicoBalm-01_6c683236-3694-4219-8fee-e969bbf9e94d_700x.jpg?v=1640436778",
name: "THE LIP BALM - 5gm",
description: "Hydrating & Nourishing",
price: "158",
stackedPrice: "₹ 225",
rating: "4.7 ★",
productID: "S-07",
hoverUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/NicoBalm-02_93beb060-c566-487f-91cf-254d5f81c1e6_360x.jpg?v=1641286093"},
{imageUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/Anti-Acne-Face-wash_-Anti-Acne-Face-Gel-Cream-Combo_700x.jpg?v=1647864525",
name: "ANTI ACNE, PIMPLE SCARS SPOTS REMOVAL COMBO",
description: "Anti Acne, Pimple Scar Spots Removal Combo",
price: "489",
stackedPrice: "₹ 698",
rating: "4.7 ★",
productID: "S-08",
hoverUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/Acne-Be-Gone-Combo-02_360x.jpg?v=1651698205"},
{imageUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/De-TanFacePack-01_700x.jpg?v=1652168815",
name: "ANTI ACNE, PIMPLE SCARS SPOTS REMOVAL COMBO",
description: "Anti Acne, Pimple Scar Spots Removal Combo",
price: "279",
stackedPrice: "₹ 399",
rating: "4.7 ★",
productID: "S-09",
hoverUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/De-TanFacePack-02_360x.jpg?v=1652168815"},
{imageUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/AntiAcneFaceWash-01_700x.jpg?v=1651698225",
name: "DE TAN FACE PACK FOR GLOWING SKIN,100gm",
description: "Detan & Skin Brightening",
price: "209",
stackedPrice: "₹ 299",
rating: "4.7 ★",
productID: "S-10",
hoverUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/Anti-AcneFaceWash-02_f9aa022d-5d4e-4703-b889-7c62aa59b206_360x.jpg?v=1652182647"},
{imageUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/C-GlowFaceSerum-01_1_700x.jpg?v=1651698248",
name: "C-GLOW FACE SERUM ,30ml",
description: "Brightening & Anti Pigmentation",
price: "263",
stackedPrice: "₹ 599",
rating: "4.7 ★",
productID: "S-11",
hoverUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/C-GlowFaceSerum-06_9d045130-dcb9-4c59-aa41-12ef9cafcdd1_360x.jpg?v=1652182969"},
{imageUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/C-Glow-Face-Wash_-Exfoliate-Scrub-Combo_700x.jpg?v=1647864479",
name: "NATURAL ANTI POLLUTION COMBO",
description: "C-Glow Face Wash & Exfoliate Face & Body Scrub",
price: "367",
stackedPrice: "₹ 599",
rating: "4.7 ★",
productID: "S-12",
hoverUrl: "https://cdn.shopify.com/s/files/1/0054/6665/2718/products/Brighter-Days-Combo-02_360x.jpg?v=1651698233"},
]
let cart = JSON.parse(localStorage.getItem("cartData")) || [];
skinData.forEach(display);
function display(elem){
let div = document.createElement("div");
let img = document.createElement("img");
img.setAttribute("src",elem.imageUrl);
let name = document.createElement("h5");
name.innerText = elem.name
let description = document.createElement("p");
description.innerText = elem.description
let prdiv = document.createElement("div");
let price = document.createElement("h4");
let rupee = document.createElement("h4");
rupee.innerText = "₹"
price.innerText = elem.price;
let stackedprice = document.createElement("p");
stackedprice.innerText = elem.stackedPrice;
let rating= document.createElement("h3");
rating.innerText = elem.rating;
let cartButton = document.createElement("button");
cartButton.innerText = "ADD TO CART";
document.querySelector("#container").append(div)
div.append(img,name,description,prdiv,cartButton)
prdiv.append(rupee,price,stackedprice,rating)
cartButton.addEventListener("click",function(){
if(check()){
alert("ALREADY ADDED TO CART")
}else{
cart.push(elem)
localStorage.setItem("cartData",JSON.stringify(cart))
window.location.href="cart.html"
}
})
function check(){
for(let i=0; i<cart.length; i++){
if(cart[i].productID == elem.productID){
return true;
}
}
return false;
}
div.addEventListener("mouseover",mouseOn)
function mouseOn(){
div.style.cursor = "pointer"
img.setAttribute("src",elem.hoverUrl)
}
div.addEventListener("mouseout",mouseoff)
function mouseoff(){
img.setAttribute("src",elem.imageUrl)
}
img.addEventListener("click",redirect)
name.addEventListener("click",redirect)
function redirect(){
localStorage.setItem("desciption",JSON.stringify(elem))
window.location.href = "skin-description/s-12.html"
}
// /////////////////////////////////////////
document.querySelector("#featured").addEventListener("change", function(){
filterit(document.querySelector("#featured").value,skinData)
})
/* filtred run program */
function filterit(getvalue,skinData){
if(getvalue=="Alpha"){
filterbyAZ(skinData)
}else if(getvalue=="rev Alpha"){
filterbyZA(skinData)
}else if(getvalue=="LH"){
filterbyLH(skinData)
}else if(getvalue=="HL"){
filterbyHL(skinData)
}
}
/* Sorting Functions */
/* Alphabatic */
function filterbyAZ(skinData){
let filter = skinData.sort(function(a,b){
if(a.name>b.name) return 1
if(a.name<b.name) return -1
return 0
})
document.querySelector("#container").innerHTML = ""
filter.forEach(display)
}
function filterbyZA(skinData){
let filter = skinData.sort(function(a,b){
if(a.name>b.name) return -1
if(a.name<b.name) return 1
return 0
})
document.querySelector("#container").innerHTML = ""
filter.forEach(display)
}
/* Price based */
function filterbyLH(skinData){
let filter = skinData.sort(function(a,b){
return a.price - b.price
})
document.querySelector("#container").innerHTML = ""
filter.forEach(display)
}
function filterbyHL(skinData){
let filter = skinData.sort(function(a,b){
return b.price - a.price
})
document.querySelector("#container").innerHTML = ""
filter.forEach(display)
}
}