Skip to content

A free, self-hostable news aggregator…

Dispatch a JS event when an entry finishes being marked read/unread (#9031)

Gerard Alvear Porras28bc73afed06
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5a43d5a69..490ef76e6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,6 +31,8 @@ See also [the FreshRSS releases](https://github.com/FreshRSS/FreshRSS/releases).
* Always jump article to top when header is offscreen, also when **Stick the article to the top when opened* is disabled [#8870](https://github.com/FreshRSS/FreshRSS/pull/8870)
* Fix padding for `.nav_menu` in Alternative-Dark, Flat, and Nord themes [#8901](https://github.com/FreshRSS/FreshRSS/pull/8901)
* Various UI and style improvements: [#8823](https://github.com/FreshRSS/FreshRSS/pull/8823), [#8824](https://github.com/FreshRSS/FreshRSS/pull/8824)
+* Extensions
+ * New `freshrss:entryStateChange` JavaScript event for extensions, dispatched when an article has finished being marked as read/unread [#8862](https://github.com/FreshRSS/FreshRSS/pull/9031)
* I18n
* Improve Hungarian [#8879](https://github.com/FreshRSS/FreshRSS/pull/8879)
* Improve Italian [#8880](https://github.com/FreshRSS/FreshRSS/pull/8880)
diff --git a/CREDITS.md b/CREDITS.md
index c0ba9f73b..687031f6d 100644
--- a/CREDITS.md
+++ b/CREDITS.md
@@ -106,6 +106,7 @@ People are sorted by name so please keep this order.
* [FromTheMoon85](https://github.com/FromTheMoon85): [contributions](https://github.com/FreshRSS/FreshRSS/pulls?q=is:pr+author:FromTheMoon85)
* [Gabriele Biggio](https://github.com/gabbihive): [contributions](https://github.com/FreshRSS/FreshRSS/pulls?q=is:pr+author:gabbihive)
* [Gaurav Thakur](https://github.com/notfoss): [contributions](https://github.com/FreshRSS/FreshRSS/pulls?q=is:pr+author:notfoss), [Web](https://blog.notfoss.com/)
+* [Gerard Alvear](https://github.com/Elgeryy1): [contributions](https://github.com/FreshRSS/FreshRSS/pulls?q=is:pr+author:Elgeryy1)
* [Gianni Scolaro](https://github.com/giannidsp): [contributions](https://github.com/FreshRSS/FreshRSS/pulls?q=is:pr+author:giannidsp)
* [Glyn Normington](https://github.com/glyn): [contributions](https://github.com/FreshRSS/FreshRSS/pulls?q=is:pr+author:glyn), [Web](https://underlap.org/)
* [Gregor Nathanael Meyer](https://github.com/spackmat): [contributions](https://github.com/FreshRSS/FreshRSS/pulls?q=is:pr+author:spackmat), [Web](https://der-meyer.de)
diff --git a/docs/en/developers/03_Backend/05_Extensions.md b/docs/en/developers/03_Backend/05_Extensions.md
index 54fc1cbfa..02a31f83e 100644
--- a/docs/en/developers/03_Backend/05_Extensions.md
+++ b/docs/en/developers/03_Backend/05_Extensions.md
@@ -225,6 +225,7 @@ if (document.readyState && document.readyState !== 'loading' && typeof window.co
The following events are available:
* `freshrss:globalContextLoaded`: will be dispatched after load the global `context` variable, useful for referencing variables injected with the `Minz_HookType::JsVars` hook.
+* `freshrss:entryStateChange`: will be dispatched on `document` after an entry has finished being marked as read or unread (i.e. once the underlying AJAX request has completed). The `detail` property of the event contains `id` (the entry ID) and `isRead` (the new read state). Useful for extensions that display their own read/unread indicator outside of the main article list, e.g. in a custom reading pane.
### Injecting CDN content
diff --git a/p/scripts/main.js b/p/scripts/main.js
index b8ea9cda9..871e9b4e1 100644
--- a/p/scripts/main.js
+++ b/p/scripts/main.js
@@ -289,6 +289,13 @@ async function send_mark_read_queue(queue, asRead, callback) {
incUnreadsFeed(div, feed_id, inc);
}
delete pending_entries['flux_' + queue[i]];
+ // Let extensions know an entry finished being marked as read/unread
+ document.dispatchEvent(new CustomEvent('freshrss:entryStateChange', {
+ detail: {
+ id: queue[i],
+ isRead: !div.classList.contains('not_read'),
+ },
+ }));
}
faviconNbUnread();
if (json.tags) {