+15
-3
api.js
+15
-3
api.js
···
290
290
return await this.getRequest('app.bsky.notification.listNotifications', params);
291
291
}
292
292
293
-
/** @param {string} [cursor], @returns {Promise<{ cursor: string | undefined, posts: json[] }>} */
293
+
/**
294
+
* @param {string} [cursor]
295
+
* @returns {Promise<{ cursor: string | undefined, posts: json[] }>}
296
+
*/
294
297
295
298
async loadMentions(cursor) {
296
299
let response = await this.loadNotifications(cursor);
···
306
309
return { cursor: response.cursor, posts };
307
310
}
308
311
309
-
/** @param {number} days, @returns {Promise<json[]>} */
312
+
/**
313
+
* @param {number} days
314
+
* @param {{ onPageLoad?: FetchAllOnPageLoad }} [options]
315
+
* @returns {Promise<json[]>}
316
+
*/
310
317
311
318
async loadTimeline(days, options = {}) {
312
319
let now = new Date();
···
322
329
});
323
330
}
324
331
325
-
/** @param {string} did, @param {number} days, @returns {Promise<json[]>} */
332
+
/**
333
+
* @param {string} did
334
+
* @param {number} days
335
+
* @param {{ onPageLoad?: FetchAllOnPageLoad }} [options]
336
+
* @returns {Promise<json[]>}
337
+
*/
326
338
327
339
async loadUserTimeline(did, days, options = {}) {
328
340
let now = new Date();
+18
-4
like_stats_page.js
+18
-4
like_stats_page.js
···
16
16
this.appView = new BlueskyAPI('public.api.bsky.app', false);
17
17
18
18
this.setupEvents();
19
+
20
+
this.progressPosts = 0;
21
+
this.progressLikeRecords = 0;
22
+
this.progressPostLikes = 0;
19
23
}
20
24
21
25
setupEvents() {
···
45
49
show() {
46
50
this.pageElement.style.display = 'block';
47
51
}
52
+
53
+
/** @returns {Promise<void>} */
48
54
49
55
async findLikes() {
50
56
this.submitButton.value = 'Cancel';
···
80
86
this.scanStartTime = undefined;
81
87
}
82
88
89
+
/** @param {number} requestedDays, @returns {Promise<json[]>} */
90
+
83
91
async fetchGivenLikes(requestedDays) {
84
-
let now = new Date().getTime();
92
+
let startTime = /** @type {number} */ (this.scanStartTime);
85
93
86
94
return await accountAPI.fetchAll('com.atproto.repo.listRecords', {
87
95
repo: accountAPI.user.did,
···
89
97
limit: 100
90
98
}, {
91
99
field: 'records',
92
-
breakWhen: (x) => Date.parse(x['value']['createdAt']) < now - 86400 * requestedDays * 1000,
100
+
breakWhen: (x) => Date.parse(x['value']['createdAt']) < startTime - 86400 * requestedDays * 1000,
93
101
onPageLoad: (data) => {
94
102
if (data.length == 0) { return }
95
103
96
104
let last = data[data.length - 1];
97
105
let lastDate = Date.parse(last.value.createdAt);
98
106
99
-
let daysBack = (this.scanStartTime - lastDate) / 86400 / 1000;
107
+
let daysBack = (startTime - lastDate) / 86400 / 1000;
100
108
this.updateProgress({ likeRecords: Math.min(1.0, daysBack / requestedDays) });
101
109
}
102
110
});
103
111
}
112
+
113
+
/** @param {number} requestedDays, @returns {Promise<json[]>} */
104
114
105
115
async fetchReceivedLikes(requestedDays) {
116
+
let startTime = /** @type {number} */ (this.scanStartTime);
117
+
106
118
let myPosts = await this.appView.loadUserTimeline(accountAPI.user.did, requestedDays, {
107
119
onPageLoad: (data) => {
108
120
if (data.length == 0) { return }
···
111
123
let lastTimestamp = last.reason ? last.reason.indexedAt : last.post.record.createdAt;
112
124
let lastDate = Date.parse(lastTimestamp);
113
125
114
-
let daysBack = (this.scanStartTime - lastDate) / 86400 / 1000;
126
+
let daysBack = (startTime - lastDate) / 86400 / 1000;
115
127
this.updateProgress({ posts: Math.min(1.0, daysBack / requestedDays) });
116
128
}
117
129
});
···
164
176
this.progressLikeRecords = 0;
165
177
this.progressPostLikes = 0;
166
178
}
179
+
180
+
/** @param {{ posts?: number, likeRecords?: number, postLikes?: number }} data */
167
181
168
182
updateProgress(data) {
169
183
if (data.posts) {
+3
-1
minisky.js
+3
-1
minisky.js
···
180
180
}
181
181
182
182
/**
183
+
* @typedef {(obj: json[]) => { cancel: true } | void} FetchAllOnPageLoad
184
+
*
183
185
* @typedef {MiniskyOptions & {
184
186
* field: string,
185
187
* breakWhen?: (obj: json) => boolean,
186
-
* onPageLoad?: (obj: json[]) => { cancel: true },
188
+
* onPageLoad?: FetchAllOnPageLoad | undefined
187
189
* }} FetchAllOptions
188
190
*
189
191
* @param {string} method