-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomain_api.js
376 lines (307 loc) · 17.8 KB
/
domain_api.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
var input = document.getElementById("domain_search");
//popular bundle .com, .net, .org
function showPopularBundle() {
let popularItemDiv = document.getElementsByClassName('popular_tld');
let popularItem = [];
var dm_bundle_price = 0;
// document.getElementsByClassName('popular_bundle')[0].innerHTML = "";
document.getElementsByClassName('dm_result_bundle')[0].innerHTML = '';
//domain price
const domainPrice = {
'com': '250',
'net': '180',
'org': '200',
};
document.getElementsByClassName('dm_result_bundle')[0].innerHTML = '';
// let popularItemDiv = document.getElementsByClassName('popular_tld')[0].dataset.tld;
if (popularItemDiv.length > 0) {
let html = [];
html =
`
<div class="dm_element">
<!-- left domain info -->
<div style="display: flex;align-items: center;" class="dm_element_left">
<div style="padding:8px 15px" >
<div class='dm_name popular_bundle' style="color:black; margin-bottom:5px"></div>
<div class="availability" style="color:black">
For registration only. Renewals are normal price.
</div>
</div>
</div>
<!-- right price and card btn -->
<div class="dm_element_right " >
<div class="dm_price dm_bundle_price">
</div>
<div class="dm_btn">
<i class="fa-solid fa-plus"></i>
</div>
</div>
</div>
`;
document.getElementsByClassName('dm_result_bundle')[0].innerHTML = html;
for (let a = 0; a < popularItemDiv.length; a++) {
// popularItem.push(popularItemDiv[a].dataset.tld);
document.getElementsByClassName('popular_bundle')[0].innerHTML += "." + popularItemDiv[a].dataset.tld + " ";
dm_bundle_price += parseInt(domainPrice[popularItemDiv[a].dataset.tld]);
document.getElementsByClassName('dm_bundle_price')[0].innerHTML = dm_bundle_price + " TK";
}
// console.log(domainPrice['dataset.tld']);
} else {
html =
`
<div class="dm_element" style="margin-top:3px !important; border-radius:8px; overflow:hidden;">
<!-- left domain info -->
<div style="display: flex;align-items: center;" class="dm_element_left">
<div style="padding:8px 15px" >
<div class='dm_name popular_bundle' style="color:red; margin-bottom:5px">No Bundle Were Found !</div>
<div class="availability" style="color:red">
</div>
</div>
</div>
<!-- right price and card btn -->
<div class="dm_element_right " >
<div class="dm_price dm_bundle_price">
</div>
</div>
</div>
`;
document.getElementsByClassName('dm_result_bundle')[0].innerHTML = html;
}
}
function hasPreviousSearch() {
let input = document.getElementById("domain_search");
let hasLocalSearchItem = localStorage.getItem("domainSearch");
// console.log(hasLocalSearchItem);
if (input.value != "") {
//if input aren't empty
localStorage.removeItem('domainCard'); //clear card
localStorage.setItem('domainSearch', JSON.stringify(input.value)); //get localstorage
doApi(input.value);
} else {
//has input value
if (hasLocalSearchItem != null) { //localstorage is present
if (hasLocalSearchItem != "") { //localstorate not empty;
let getLocalSearchItem = JSON.parse(hasLocalSearchItem);
input.value = getLocalSearchItem;
doApi(getLocalSearchItem);
}
}
}
}
hasPreviousSearch();
/*
this hasPreviousSearch() function check if input is empty or not;
if empty then check any data save info localstorage in browser;
if input empty and localstorage present it call doApi() function with localdata,
if input empty and localstorage are not present nothing happen;
if there is no localdata present and input not empty, it call doApi() with input value, and save data to localstorage;;
*/
//main api function
function doApi(localSearchData) {
//api required data
const X_RapidAPI_Key = '9715ad5b67msh29e1ed7d944594ep10ae37jsna4e2df913318';
const X_RapidAPI_host = 'domainr.p.rapidapi.com';
const apiUriSearch = 'https://domainr.p.rapidapi.com/v2/search';
const apiUriStatus = 'https://domainr.p.rapidapi.com/v2/status';
// const query = event.target.value;
const query = localSearchData ? localSearchData : document.getElementById('domain_search').value;
// const ablDomain = document.getElementsByClassName('availability');
// const dm_element = document.getElementsByClassName('dm_element');
// const dm_icon = document.getElementsByClassName('dm_icon');
// const cardBtn = document.getElementsByClassName('addToCard');
const domainPrice = {
'com': '250 TK',
'net': '180 TK',
'org': '200 TK',
};
if (query != "") { //input not empty
/**
* make ajux for searching domain
* this ajux call an api and get all relative domain against input value;
*/
axios.get(apiUriSearch, {
params: {
'mashape-key': '9715ad5b67msh29e1ed7d944594ep10ae37jsna4e2df913318',
'query': query,
},
headers: {
'X-RapidAPI-Key': X_RapidAPI_Key,
'X-RapidAPI-Host': X_RapidAPI_host,
}
})
.then((response) => {
// console.log(response.data.results);
let Html = [];
document.getElementsByClassName('dm_result_popular')[0].innerHTML = '';
response.data.results.forEach((element, index) => {
// console.log(element);
//show ajux loading
// ablDomain[index].innerHTML = 'Finding ..'
/**
* we get enough data by response.
* but we dosn't get any domain are available or not.
* so we have to call another api to get this domain are active or not.
* we foreach all response an get domain active or not.
*/
axios.get(apiUriStatus, {
params: {
'mashape-key': '9715ad5b67msh29e1ed7d944594ep10ae37jsna4e2df913318',
'domain': element.domain,
},
headers: {
'X-RapidAPI-Key': X_RapidAPI_Key,
'X-RapidAPI-Host': X_RapidAPI_host,
}
})
.then((response) => {
// console.log(response.data.status[0].zone);
// console.log(ablDomain[abl]);
// let Dname = response.data.status[0].zone;
if (response.data.status[0].zone == 'com' || response.data.status[0].zone == "net" || response.data.status[0].zone == "org") {
//if TLD is .com or .net or .org
if (response.data.status[0].summary == 'inactive') { //if TLD .com, .net, .org are not active. availabel for purches now.
let popData =
`
<div class="dm_element">
<!-- left domain info -->
<div style="display: flex;align-items: center;" class="dm_element_left">
<div class="dm_icon" style="color:green"><i class="fa-solid fa-circle-check"></i></div>
<div style="padding:3px" >
<div class='dm_name' style="color:green">${element.domain}</div>
<div class="availability" style="color:green">
Buy Now
</div>
</div>
</div>
<!-- right price and card btn -->
<div class="dm_element_right " >
<div class="dm_price">
${domainPrice[element.zone] ?? "10"}
</div>
<div class="dm_btn addToCard ${element.domain} popular_tld" data-tld="${element.zone}" data-active="yes" data-price="${domainPrice[element.zone] ?? '10'}" data-vat="5" data-name="${element.domain}" onclick="addToCard(this)">
<i class="fa-solid fa-plus"></i>
</div>
</div>
</div>
`;
document.getElementsByClassName('dm_result_popular')[0].innerHTML += popData;
} else {
let popData =
`<div class="dm_element">
<!-- left domain info -->
<div style="display: flex;align-items: center;" class="dm_element_left">
<div class="dm_icon" style="color:red"><i class="fa-solid fa-circle-xmark"></i></div>
<div style="padding:3px" >
<div class='dm_name' style="color:red">${element.domain}</div>
<div class="availability" style="color:red">
Already Sold
</div>
</div>
</div>
<!-- right price and card btn -->
<div class="dm_element_right " >
<div class="dm_price">
${domainPrice[element.zone] ?? "10"}
</div>
<div class="dm_btn addToCard ${element.domain}" data-price="${domainPrice[element.zone] ?? '10'}" data-vat="5" data-name="${element.domain}" data-i="${index}" onclick="addToCard(this)">
<i class="fa-solid fa-plus"></i>
</div>
</div>
</div>
`;
document.getElementsByClassName('dm_result_popular')[0].innerHTML += popData;
}
// console.log('get');
} else { //TLD are not .com or .net or .org
if (response.data.status[0].summary == 'inactive') {
// console.log(response.data.status[0]);
// let bundleHtml = [];
Html +=
`
<div class="dm_element">
<!-- left domain info -->
<div style="display: flex;align-items: center;" class="dm_element_left">
<div class="dm_icon" style="color:green"><i class="fa-solid fa-circle-check"></i></div>
<div style="padding:3px" >
<div class='dm_name' style="color:green">${element.domain}</div>
<div class="availability" style="color:green">
Buy Now
</div>
</div>
</div>
<!-- right price and card btn -->
<div class="dm_element_right " >
<div class="dm_price">
${domainPrice[element.zone]?? '10 TK'}
</div>
<div class="dm_btn addToCard ${element.domain}" data-price="${domainPrice[element.zone] ?? '10'}" data-vat="5" data-name="${element.domain}" onclick="addToCard(this)">
<i class="fa-solid fa-plus"></i>
</div>
</div>
</div>
`;
document.getElementById('ds_result_show').innerHTML = Html;
// ablDomain[index].innerHTML = 'Buy Now'
// dm_element[index].style.color = 'green';
// dm_icon[index].innerHTML =
// `<i class="fa-solid fa-circle-check"></i>`;
// dm_icon[index].style.color = 'green';
} else {
Html +=
`
<div class="dm_element">
<!-- left domain info -->
<div style="display: flex;align-items: center;" class="dm_element_left">
<div class="dm_icon" style="color:red"><i class="fa-solid fa-circle-xmark"></i></div>
<div style="padding:3px" >
<div class='dm_name' style="color:red">${element.domain}</div>
<div class="availability" style="color:red">
Already Sold
</div>
</div>
</div>
<!-- right price and card btn -->
<div class="dm_element_right " >
<div class="dm_price">
${domainPrice[element.zone] ?? "10 TK"}
</div>
<div class="dm_btn addToCard ${element.domain}" data-price="${domainPrice[element.zone] ?? '10'}" data-vat="5" data-name="${element.domain}" data-i="${index}" onclick="addToCard(this)">
<i class="fa-solid fa-plus"></i>
</div>
</div>
</div>
`;
document.getElementById('ds_result_show').innerHTML = Html;
// document.getElementById('ds_result_show').innerHTML = Html;
// dm_icon[index].innerHTML =
// `<i class="fa-solid fa-circle-xmark"></i>`;
// dm_icon[index].style.color = 'red';
// dm_element[index].style.color = 'red';
// ablDomain[index].innerHTML = 'Already Sold'
}
}
// cardBtn[index].setAttribute('data-name', Dname);
// cardBtn[index].setAttribute('data-price', '50');
// cardBtn[index].setAttribute('data-vat', '0');
showPopularBundle();
})
});
})
.then((error) => {
console.log(error);
})
} else { //if input value is empty
document.getElementById('ds_result_show').innerHTML = '';
}
}
// Execute a function when the user presses a key on the keyboard
input.addEventListener("keypress", function (event) {
// If the user presses the "Enter" key on the keyboard
if (event.key === "Enter") {
hasPreviousSearch();
/**
* exicute this function directly if click on search icon.
*
*/
};
});