From 9bf54c51f2fb04ea8ec22d6fea8c09faf14b0828 Mon Sep 17 00:00:00 2001 From: Mars Date: Sun, 7 Jul 2024 17:57:03 +0200 Subject: [PATCH] Add ability to exclude reblogs/boosts --- README.md | 1 + src/client.ts | 3 ++- src/core.ts | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f8633a8..0e9e6b1 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ You can customize the feed with `data-` attributes: * `data-toot-limit`: The maximum number of toots to display. * `data-toot-account-id`: Emfed needs to make an extra API request to translate your human-readable username (like `@Mastodon`) into an internal ID (like 13179) before it can look up your toots. If you have [empathy for the machine][eftm], you can make everything faster by specifying the ID directly here. * `data-exclude-replies`: "true" or "false" according to whether or not you'd like to exclude replies. The default behavior is that replies are included. +* `data-exclude-reblogs`: "true" or "false" according to whether or not you'd like to exclude reblogs/boosts. The default behavior is that reblogs/boosts are included. Emfed sanitizes the HTML contents of toots using [DOMPurify][] to avoid malicious markup and XSS attacks. diff --git a/src/client.ts b/src/client.ts index 1e68fba..339d781 100644 --- a/src/client.ts +++ b/src/client.ts @@ -30,6 +30,7 @@ export async function getToots( accountId?: string, limit?: number, excludeReplies?: boolean, + excludeReblogs?: boolean ): Promise { const url = new URL(userURL); @@ -56,7 +57,7 @@ export async function getToots( // Fetch toots. const tootURL = Object.assign(new URL(url), { pathname: `/api/v1/accounts/${userId}/statuses`, - search: `?limit=${limit ?? 5}&exclude_replies=${!!excludeReplies}`, + search: `?limit=${limit ?? 5}&exclude_replies=${!!excludeReplies}&exclude_reblogs=${!!excludeReblogs}`, }); return await (await fetch(tootURL)).json(); diff --git a/src/core.ts b/src/core.ts index fa4dafc..fbfed59 100644 --- a/src/core.ts +++ b/src/core.ts @@ -125,6 +125,7 @@ export async function loadToots(element: Element) { el.dataset.tootAccountId, Number(el.dataset.tootLimit ?? 5), el.dataset.excludeReplies === "true", + el.dataset.excludeReblogs === "true", ); // Construct the HTML content. @@ -162,7 +163,6 @@ export async function loadTootPostAndReplies(element: Element) { */ export function loadAll() { document.querySelectorAll("a.mastodon-feed").forEach(loadToots); - /* inspired by https://carlschwan.eu/2020/12/29/adding-comments-to-your-static-blog-with-mastodon/ */ - document.querySelectorAll("a.mastodon-thread").forEach(loadTootPostAndReplies) - + /* inspired by https://carlschwan.eu/2020/12/29/adding-comments-to-your-static-blog-with-mastodon/ */ + document.querySelectorAll("a.mastodon-thread").forEach(loadTootPostAndReplies) }