-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
109 lines (83 loc) · 3.43 KB
/
script.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
$(document).ready(function() {
$("#domValue").click(function() {
if (document.getElementById("csvCheck").checked == true) {
var str = $("#dom").val().split(',');
} else {
var str = $("#dom").val().split('\n');
}
if (str.length > 0) {
$("#bulk").removeClass('hide');
}
console.log(str)
// alert(str);
function sleep() {
setTimeout(function() {
console.log("waiting");
}, 240000);
}
for (i = 0; i < str.length; ++i) {
$.getJSON('https://api.allorigins.win/get?url=' + encodeURIComponent('https://api.godaddy.com/v1/appraisal/' + str[i]), function(data) {
var gd = JSON.parse(data.contents);
var sales = '';
if (gd.status != "OK" || gd.status != "UNSUPPORTED_DOMAIN" || gd.status != "MASKED_DOMAIN" || gd.status == "SLOW_DOWN") {
sleep();
}
if (gd.domain != undefined && gd.govalue != undefined) {
if (document.getElementById("compare").checked == true) {
for (j = 0; j < gd.comparable_sales.length; ++j) {
sales += "<tr><td>" + gd.comparable_sales[j].year + " <td>" + gd.comparable_sales[j].domain + "</td><td> $" + gd.comparable_sales[j].price + "</td></tr>";
}
txt = "<tr><th scope=\"row\">" + gd.domain + "</th><td>" + gd.govalue + "</td><td><table style=\"text-align: centre\">" + "<thead scope=\"row\"><th >Year</th><th >Domain</th><th>Sale Price</th></thead><tbody>" + sales + "</tbody></table></td></tr>";
} else {
$("#remove").remove();
txt = "<tr><td>" + JSON.parse(data.contents).domain + "</td><td>" + JSON.parse(data.contents).govalue + "</td></tr>";
}
$("#bulk").append(txt);
document.querySelector('#bulk').scrollIntoView({
behavior: 'smooth'
});
}
});
}
});
});
/* CSV Import code */
function download_csv(csv, filename) {
var csvFile;
var downloadLink;
// CSV FILE
csvFile = new Blob([csv], {
type: "text/csv"
});
// Download link
downloadLink = document.createElement("a");
// File name
downloadLink.download = filename;
// We have to create a link to the file
downloadLink.href = window.URL.createObjectURL(csvFile);
// Make sure that the link is not displayed
downloadLink.style.display = "none";
// Add the link to your DOM
document.body.appendChild(downloadLink);
// Lanzamos
downloadLink.click();
}
function export_table_to_csv(html, filename) {
var csv = [];
var rows = document.querySelectorAll("table tr");
for (var i = 0; i < rows.length; i++) {
var row = [],
cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length; j++)
row.push(cols[j].innerText);
csv.push(row.join(","));
}
// Download CSV
download_csv(csv.join("\n"), filename);
}
document.getElementById('csv').addEventListener("click", function() {
var date = new Date();
var html = document.querySelector("table").outerHTML;
export_table_to_csv(html, "bulk_appraisal_" + date.getTime() + ".csv");
});
// push notification