-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
177 lines (147 loc) · 4.69 KB
/
main.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
function err() {
$(".error").show();
document.querySelector(".error").innerText = "Please enter a valid username";
}
function displayAccountDetails() {
let uname = $("#instaUsername").val();
if (uname == "") {
console.log("username is empty");
$(".accountDetails").hide();
return err();
} else {
let accounturl = "https://www.instagram.com/" + uname + "/?__a=1";
// console.log(accounturl);
fetch(accounturl)
.then(function (response) {
// The JSON data will arrive here
//if the name is not valid, throw an error
if (response.status == 404 || response.status == 400) {
$(".accountDetails").hide();
$(".error")
.show()
.html("User Doesn't Exist");
//else proceed to get the response json data
} else {
return response.json();
}
}) //once the data is succesfully pulled its then appended into object named instagram
.then(function (instagram) {
if (instagram.graphql.user.is_private == true) {
console.log("private");
$(".accountDetails").hide();
$(".error")
.show()
.html("This account is Private");
} else {
appendData(instagram);
}
})
// if anything goes wrong we can check the err msg thru catch
.catch(function (err) {
console.log("Error: " + err);
// $(".error").show().html("Oops something went wrong, try again");
});
function appendData(instagram) {
$(".error").hide();
$("#dp").html(
'<img src="' +
instagram.graphql.user.profile_pic_url_hd +
'" alt="' +
instagram.graphql.user.username +
"'s Profile pic\" >"
);
$("#username").html("<b>@" + instagram.graphql.user.username + "<b>");
$("#FullName").html("<b>" + instagram.graphql.user.full_name + "<b>");
$("#followers").html(
"<b>" + instagram.graphql.user.edge_followed_by.count + "<b>"
);
$("#following").html(
"<b>" + instagram.graphql.user.edge_follow.count + "<b>"
);
if (instagram.graphql.user.biography == null) {
$("#bio")
.html(instagram.graphql.user.biography)
.hide();
} else {
$("#bio").html(instagram.graphql.user.biography);
}
if (instagram.graphql.user.external_url == null) {
$("#website").hide();
} else {
$("#website").show();
$("#website").html(
"Website: \n" + "<b>" + instagram.graphql.user.external_url + "<b>"
);
}
$("#totalPostsUploaded").html(
"<b>" +
instagram.graphql.user.edge_owner_to_timeline_media.count +
"<b>"
);
let profileURL =
"https://instagram.com/" + instagram.graphql.user.username;
$("#visitProfile")
.prop({
href: profileURL,
title: "Opens in a new window"
})
.click(function () {
window.open(this.href);
return false;
});
if (instagram.graphql.user.edge_owner_to_timeline_media.count == 0) {
console.log("No posts");
$("#latestPost").hide();
} else {
var url =
instagram.graphql.user.edge_owner_to_timeline_media.edges[0].node
.display_url;
$("#latestPost").show();
$("#latestPost").html(
"Latest Post thumbnail: \n" +
'<img src="' +
url +
'" alt="' +
instagram.graphql.user.username +
"'s Latest Post\" >"
);
}
$(".accountDetails").show();
}
}
}
// Insta post download:
let getHDimage = function () {
let userInputURL = $("#userInputURL").val();
let trim = userInputURL.substring(0, 40);
if (userInputURL == "") {
$(".error2")
.show()
.html("Please enter a valid post url");
} else {
let HdImageURL = "media/?size=l";
let full = trim + HdImageURL;
(async () => {
const response = await fetch(full);
// console.log(response.url);
$("#imageDLURL").html('<img src="' +
response.url +
'" alt="' + "'s Latest Post\" >"
);
('<img src=' + response.url > '');
$('<a/>')
.addClass('btn-long download-btn')
.attr({
'href': response.url,
'target': '_blank',
download : true
})
.text('Download image')
.appendTo('#imageDLURL');
;
})();
$("#userInputURL").val("");
// console.log(response.url);
// return window.open(response.url);
}
}