This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
InstagramHelperDataViewer.html
365 lines (319 loc) · 16.9 KB
/
InstagramHelperDataViewer.html
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
<html>
<!-- Bootstrap Bundle -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"></script>
<!-- Jquery -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<head>
<title>InstagramHelper Data Viewer</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.chat-container {
border: 2px solid #dedede;
background-color: #f1f1f1;
border-radius: 5px;
padding: 10px;
margin: 10px 0;
}
.darker {
border-color: #ccc;
background-color: #ddd;
}
.chat-container::after {
content: "";
clear: both;
display: table;
}
.chat-container img {
float: left;
max-width: 60px;
width: 100%;
margin-right: 20px;
border-radius: 50%;
}
.chat-container img.right {
float: right;
margin-left: 20px;
margin-right: 0;
}
.time-right {
float: right;
color: #aaa;
}
.time-left {
float: left;
color: #999;
}
</style>
</head>
<body>
<div class="container">
<div class="p-5 mb-4 bg-light rounded-3">
<div class="container-fluid py-5">
<h1 class="display-5 fw-bold">Chat Messages</h1>
<p class="col-md-8 fs-4">Load the json file that you downloaded below.</p>
<form id="jsonFile" name="jsonFile" enctype="multipart/form-data" method="post">
<fieldset>
<div>
<label for="fileinput" class="form-label">InstagramHelper Data Json File</label>
<input class="form-control form-control-lg" id="fileinput" type="file">
</div>
<br>
<button class="btn btn-primary btn-lg" id='btnLoad' type="button"
onclick='loadFile();'>Load</button>
<button class="btn btn-danger btn-lg" id='btnClear' type="button"
onclick='clearChatHistory();'>Clear</button>
</fieldset>
</form>
</div>
</div>
<div id="chatMessages">
</div>
<footer class="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
<a href="https://pishangujeniya.github.io/instagram-helper/"
class="col-md-4 d-flex align-items-center justify-content-center mb-3 mb-md-0 me-md-auto text-decoration-none">©
2021 Instagram Helper</a>
<ul class="nav col-md-4 justify-content-end">
<li class="nav-item"><a href="https://www.pexels.com/photo/man-smiling-behind-wall-220453/"
class="nav-link px-2 text-muted">Avatar Placeholder - Photo by Pixabay from Pexels</a></li>
<li class="nav-item"><a href="https://www.pexels.com/photo/man-wearing-blue-crew-neck-t-shirt-2379005/"
class="nav-link px-2 text-muted">Avatar Placeholder - Photo by Italo Melo from Pexels</a></li>
</ul>
</footer>
</div>
<script type="text/javascript">
let otherAvatarPlaceholder = "https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?crop=entropy&cs=srgb&dl=pexels-pixabay-220453.jpg&fit=crop&fm=jpg&h=200&w=200";
let myAvatarPlaceholder = "https://images.pexels.com/photos/2379005/pexels-photo-2379005.jpeg?crop=entropy&cs=srgb&dl=pexels-italo-melo-2379005.jpg&fit=crop&fm=jpg&h=200&w=200"
let chatMessagesDiv = document.getElementById("chatMessages");
var allPossibleItemTypes = [
"action_log",
"text",
"link",
"media_share",
"clip",
"media",
"video_call_event",
"felix_share",
"placeholder"
];
var myUserId = 123456789;
var jsonFileData = {};
var allMessagesItemsArray = [];
var usersChatParticipants = [];
function loadFile() {
var input, file, fr;
if (typeof window.FileReader !== 'function') {
alert("The file API isn't supported on this browser yet.");
return;
}
input = document.getElementById('fileinput');
if (!input) {
alert("Um, couldn't find the fileinput element.");
}
else if (!input.files) {
alert("This browser doesn't seem to support the `files` property of file inputs.");
}
else if (!input.files[0]) {
alert("Please select a file before clicking 'Load'");
}
else {
file = input.files[0];
fr = new FileReader();
fr.onload = receivedText;
fr.readAsText(file);
}
function receivedText(e) {
let lines = e.target.result;
jsonFileData = JSON.parse(lines);
afterJsonLoad();
}
}
function getParticipantImageLink(userId) {
for (let index = 0; index < usersChatParticipants.length; index++) {
const singleUserChatParticipant = usersChatParticipants[index];
if (singleUserChatParticipant.pk == userId) {
return singleUserChatParticipant["profile_pic_url"];
}
}
return '';
}
function getErrorPlaceholderHtml(isMe = false) {
let onErrorPlaceholderHtml = "";
if (isMe) {
onErrorPlaceholderHtml = "this.src='" + myAvatarPlaceholder + "'";
} else {
onErrorPlaceholderHtml = "this.src='" + otherAvatarPlaceholder + "'";
}
return onErrorPlaceholderHtml;
}
function myTextChatBoxGenerator(avatarImgSrc, text, timestamp) {
let chatTime = new Date(timestamp / 1000).toLocaleString();
let chatBox = '<div class="chat-container darker">' +
'<img src="' + avatarImgSrc + '" onerror="' + getErrorPlaceholderHtml(true) + '" alt="Avatar" class="right" style="width:100%;">' +
'<p>' + text + '</p>' +
'<span class="time-left">' + chatTime + '</span>' +
'</div>';
return chatBox;
}
function otherTextChatBoxGenerator(avatarImgSrc, text, timestamp) {
let chatTime = new Date(timestamp / 1000).toLocaleString();
let chatBox = '<div class="chat-container">' +
'<img src="' + avatarImgSrc + '" onerror="' + getErrorPlaceholderHtml(false) + '" alt="Avatar" style="width:100%;">' +
'<p>' + text + '</p>' +
'<span class="time-right">' + chatTime + '</span>' +
'</div>';
return chatBox;
}
function myLinkChatBoxGenerator(avatarImgSrc, link_url, link_text, timestamp) {
let chatTime = new Date(timestamp / 1000).toLocaleString();
let chatBox = '<div class="chat-container darker">' +
'<img src="' + avatarImgSrc + '" onerror="' + getErrorPlaceholderHtml(true) + '" alt="Avatar" class="right" style="width:100%;">' +
'<p><a href=' + link_url + ' target="_blank">' + link_text + '</a></p>' +
'<span class="time-left">' + chatTime + '</span>' +
'</div>';
return chatBox;
}
function otherLinkChatBoxGenerator(avatarImgSrc, link_url, link_text, timestamp) {
let chatTime = new Date(timestamp / 1000).toLocaleString();
let chatBox = '<div class="chat-container">' +
'<img src="' + avatarImgSrc + '" onerror="' + getErrorPlaceholderHtml(false) + '" alt="Avatar" style="width:100%;">' +
'<p><a href=' + link_url + ' target="_blank">' + link_text + '</a></p>' +
'<span class="time-right">' + chatTime + '</span>' +
'</div>';
return chatBox;
}
function myMediaShareChatBoxGenerator(avatarImgSrc, mediaCode, mediaUserName, timestamp) {
let chatTime = new Date(timestamp / 1000).toLocaleString();
let link_url = "https://instagram.com/p/" + mediaCode;
let chatBox = '<div class="chat-container darker">' +
'<img src="' + avatarImgSrc + '" onerror="' + getErrorPlaceholderHtml(true) + '" alt="Avatar" class="right" style="width:100%;">' +
'<p> Post By <a href=' + link_url + ' target="_blank" >' + mediaUserName + '</a></p>' +
'<span class="time-left">' + chatTime + '</span>' +
'</div>';
return chatBox;
}
function otherMediaShareChatBoxGenerator(avatarImgSrc, mediaCode, mediaUserName, timestamp) {
let chatTime = new Date(timestamp / 1000).toLocaleString();
let link_url = "https://instagram.com/p/" + mediaCode;
let chatBox = '<div class="chat-container">' +
'<img src="' + avatarImgSrc + '" onerror="' + getErrorPlaceholderHtml(false) + '" alt="Avatar" style="width:100%;">' +
'<p> Post By <a href=' + link_url + ' target="_blank" >' + mediaUserName + '</a></p>' +
'<span class="time-right">' + chatTime + '</span>' +
'</div>';
return chatBox;
}
function myClipChatBoxGenerator(avatarImgSrc, clipCode, clipUsername, timestamp) {
let chatTime = new Date(timestamp / 1000).toLocaleString();
let link_url = "https://instagram.com/p/" + clipCode;
let chatBox = '<div class="chat-container darker">' +
'<img src="' + avatarImgSrc + '" onerror="' + getErrorPlaceholderHtml(true) + '" alt="Avatar" class="right" style="width:100%;">' +
'<p> Clip By <a href=' + link_url + ' target="_blank" >' + clipUsername + '</a></p>' +
'<span class="time-left">' + chatTime + '</span>' +
'</div>';
return chatBox;
}
function otherClipChatBoxGenerator(avatarImgSrc, clipCode, clipUsername, timestamp) {
let chatTime = new Date(timestamp / 1000).toLocaleString();
let link_url = "https://instagram.com/p/" + clipCode;
let chatBox = '<div class="chat-container">' +
'<img src="' + avatarImgSrc + '" onerror="' + getErrorPlaceholderHtml(false) + '" alt="Avatar" style="width:100%;">' +
'<p> Clip By <a href=' + link_url + ' target="_blank" >' + clipUsername + '</a></p>' +
'<span class="time-right">' + chatTime + '</span>' +
'</div>';
return chatBox;
}
function myMediaChatBoxGenerator(avatarImgSrc, timestamp) {
let chatTime = new Date(timestamp / 1000).toLocaleString();
let chatBox = '<div class="chat-container darker">' +
'<img src="' + avatarImgSrc + '" onerror="' + getErrorPlaceholderHtml(true) + '" alt="Avatar" class="right" style="width:100%;">' +
'<p>---PRIVATE MEDIA SHARED---</p>' +
'<span class="time-left">' + chatTime + '</span>' +
'</div>';
return chatBox;
}
function otherMediaChatBoxGenerator(avatarImgSrc, timestamp) {
let chatTime = new Date(timestamp / 1000).toLocaleString();
let chatBox = '<div class="chat-container">' +
'<img src="' + avatarImgSrc + '" onerror="' + getErrorPlaceholderHtml(false) + '" alt="Avatar" style="width:100%;">' +
'<p>---PRIVATE MEDIA SHARED---</p>' +
'<span class="time-right">' + chatTime + '</span>' +
'</div>';
return chatBox;
}
function afterJsonLoad() {
allMessagesItemsArray = jsonFileData["allMessagesItemsArray"];
myUserId = jsonFileData["myUserId"];
usersChatParticipants = jsonFileData["usersChatParticipants"];
loadMessages();
}
function loadMessages() {
clearChatHistory();
for (let index = allMessagesItemsArray.length - 1; index >= 0; index--) {
const element = allMessagesItemsArray[index];
const div = document.createElement('div');
let appendInnerHtml = "";
if (myUserId == element["user_id"]) {
let myProfilePic = getParticipantImageLink(myUserId);
// Me
if (element["item_type"] == "text") {
const text = element["text"];
const timestamp = element["timestamp"];
appendInnerHtml = myTextChatBoxGenerator(myProfilePic, text, timestamp);
} else if (element["item_type"] == "link") {
const linkUrl = element["link"]["link_context"]["link_url"];
const linkTitle = element["link"]["link_context"]["link_title"];
const timestamp = element["timestamp"];
appendInnerHtml = myLinkChatBoxGenerator(myProfilePic, linkUrl, linkTitle, timestamp);
} else if (element["item_type"] == "media_share") {
const mediaCode = element["media_share"]["code"];
const mediaUserName = element["media_share"]["user"]["username"];
const timestamp = element["timestamp"];
appendInnerHtml = myMediaShareChatBoxGenerator(myProfilePic, mediaCode, mediaUserName, timestamp);
} else if (element["item_type"] == "clip") {
const mediaCode = element["clip"]["clip"]["code"];
const mediaUserName = element["clip"]["clip"]["user"]["username"];
const timestamp = element["timestamp"];
appendInnerHtml = myClipChatBoxGenerator(myProfilePic, mediaCode, mediaUserName, timestamp);
} else if (element["item_type"] == "media") {
const timestamp = element["timestamp"];
appendInnerHtml = myMediaChatBoxGenerator(myProfilePic, timestamp);
}
} else {
// Other
if (element["item_type"] == "text") {
const text = element["text"];
const timestamp = element["timestamp"];
appendInnerHtml = otherTextChatBoxGenerator(getParticipantImageLink(element["user_id"]), text, timestamp);
} else if (element["item_type"] == "link") {
const linkUrl = element["link"]["link_context"]["link_url"];
const linkTitle = element["link"]["link_context"]["link_title"];
const timestamp = element["timestamp"];
appendInnerHtml = otherLinkChatBoxGenerator(getParticipantImageLink(element["user_id"]), linkUrl, linkTitle, timestamp);
} else if (element["item_type"] == "media_share") {
const mediaCode = element["media_share"]["code"];
const mediaUserName = element["media_share"]["user"]["username"];
const timestamp = element["timestamp"];
appendInnerHtml = otherMediaShareChatBoxGenerator(getParticipantImageLink(element["user_id"]), mediaCode, mediaUserName, timestamp);
} else if (element["item_type"] == "clip") {
const mediaCode = element["clip"]["clip"]["code"];
const mediaUserName = element["clip"]["clip"]["user"]["username"];
const timestamp = element["timestamp"];
appendInnerHtml = otherClipChatBoxGenerator(getParticipantImageLink(element["user_id"]), mediaCode, mediaUserName, timestamp);
} else if (element["item_type"] == "media") {
const timestamp = element["timestamp"];
appendInnerHtml = otherMediaChatBoxGenerator(getParticipantImageLink(element["user_id"]), timestamp);
}
}
div.innerHTML = appendInnerHtml;
chatMessagesDiv.appendChild(div);
}
}
function clearChatHistory() {
chatMessagesDiv.innerHTML = "";
}
</script>
</body>
</html>