+16
-6
skythread.js
+16
-6
skythread.js
···
75
75
return post;
76
76
}
77
77
78
-
function buildElementForTree(post) {
78
+
function buildElementForTree(post, root) {
79
79
let div = document.createElement('div');
80
80
div.className = 'post';
81
81
82
-
let formattedTime = post.createdAt.toLocaleString(window.dateLocale, {
83
-
day: 'numeric', month: 'short', hour: 'numeric', minute: 'numeric'
84
-
});
82
+
let timeFormat = (post !== root && sameDay(post.createdAt, root.createdAt)) ?
83
+
{ hour: 'numeric', minute: 'numeric' } :
84
+
{ day: 'numeric', month: 'short', hour: 'numeric', minute: 'numeric' };
85
+
86
+
let formattedTime = post.createdAt.toLocaleString(window.dateLocale, timeFormat);
85
87
let isoTime = post.createdAt.toISOString();
86
88
let url = post.uri.replace('at://', 'https://staging.bsky.app/profile/').replace('app.bsky.feed.post', 'post');
87
89
let profileURL = 'https://staging.bsky.app/profile/' + post.author.handle;
···
111
113
div.appendChild(stats);
112
114
113
115
for (let reply of post.replies) {
114
-
let subdiv = buildElementForTree(reply);
116
+
let subdiv = buildElementForTree(reply, root);
115
117
div.appendChild(subdiv);
116
118
}
117
119
···
143
145
return location.origin + '/' + location.pathname;
144
146
}
145
147
148
+
function sameDay(date1, date2) {
149
+
return (
150
+
date1.getDate() == date2.getDate() &&
151
+
date1.getMonth() == date2.getMonth() &&
152
+
date1.getFullYear() == date2.getFullYear()
153
+
);
154
+
}
155
+
146
156
function loadThread(url) {
147
157
loadThreadJSON(url).then(json => {
148
158
let tree = buildPostTree(json);
···
155
165
document.body.appendChild(p);
156
166
}
157
167
158
-
let list = buildElementForTree(tree);
168
+
let list = buildElementForTree(tree, tree);
159
169
document.body.appendChild(list);
160
170
}).catch(error => {
161
171
console.log(error);