Skip to content

Commit

Permalink
feat: add more clarity in labels and inverts one setting
Browse files Browse the repository at this point in the history
  • Loading branch information
kalvn committed May 25, 2024
1 parent e184a06 commit 3eab804
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 24 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## [v1.1.1](https://github.com/kalvn/freshrss-mark-previous-as-read/releases/tag/v1.1.1) - 2024-05-25
### Changed
- Inverted settings to choose between all previous entries and only those belonging to the same feed for more clarity.
- Improved configuration layout.
- Improved translations.

### Fixed
- Translations for alert shown when the button is clicked.


## [v1.1.0](https://github.com/kalvn/freshrss-mark-previous-as-read/releases/tag/v1.1.0) - 2024-05-20
### Added
- French translation.
Expand All @@ -10,13 +20,16 @@
### Changed
- The icon is now more meaningful.


## [v1.0.2](https://github.com/kalvn/freshrss-mark-previous-as-read/releases/tag/v1.0.2) - 2024-05-09
### Added
- An icon to the left of the button.


## [v1.0.1](https://github.com/kalvn/freshrss-mark-previous-as-read/releases/tag/v1.0.1) - 2024-05-09
### Fixed
- Add button to new entries loaded dynamically when scrolling.


## [v1.0.0](https://github.com/kalvn/freshrss-mark-previous-as-read/releases/tag/v1.0.0) - 2024-02-05
Initial version.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# FreshRSS extension - Mark Previous as Read
This extension adds a button in the footer of each entry. Clicking this button will mark all previous entries belonging to the current feed, as read.
This extension adds a button in the footer of each entry. Clicking this button will mark all previous entries as read.

The goal is, when going through a very long list of entries without reading them all, to be able to mark as read what was went through, and continue later.

## Installation
Download the code and copy directory `xExtension-MarkPreviousAsRead` into the `extensions/` directory of your FreshRSS installation.

Then, in the settings menu, select **Extensions** and enable **Mark Previous as Read**.

## Configuration
Head to `https://<your hostname>/i/?c=extension` and click on **Mark Previous as Read** settings icon.

- **Show a validation popup before marking entries as read.**: shows an alert when the button is clicked, as a last chance to change your mind or cancel in case you mis-clicked.
- **Apply only to entries that belong to the same feed.**: mark as read only entries that belong to the same feed as the one currently open.
16 changes: 10 additions & 6 deletions xExtension-MarkPreviousAsRead/configure.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
<form action="<?= _url('extension', 'configure', 'e', urlencode($this->getName())) ?>" method="post">
<input type="hidden" name="_csrf" value="<?= FreshRSS_Auth::csrfToken() ?>" />
<div class="form-group">
<label class="group-name" for="enable-warning-popup"><?= _t('ext.config.enableWarningPopup') ?></label>
<div class="group-controls">
<input type="checkbox" name="enable-warning-popup" id="enable-warning-popup" value="1" <?= FreshRSS_Context::userConf()->enable_warning_popup ? 'checked' : '' ?>>
<div class="group-controls mark-previous-as-read-settings">
<label class="checkbox" for="enable-warning-popup">
<input type="checkbox" name="enable-warning-popup" id="enable-warning-popup" value="1" <?= FreshRSS_Context::userConf()->enable_warning_popup ? 'checked' : '' ?>>
<?= _t('ext.config.enableWarningPopup') ?>
</label>
</div>
</div>

<div class="form-group">
<label class="group-name" for="apply-to-all-entries-above"><?= _t('ext.config.applyToAllEntriesAbove') ?></label>
<div class="group-controls">
<input type="checkbox" name="apply-to-all-entries-above" id="apply-to-all-entries-above" value="1" <?= FreshRSS_Context::userConf()->apply_to_all_entries_above ? 'checked' : '' ?>>
<div class="group-controls mark-previous-as-read-settings">
<label class="checkbox" for="apply-only-to-same-feed-entries">
<input type="checkbox" name="apply-only-to-same-feed-entries" id="apply-only-to-same-feed-entries" value="1" <?= FreshRSS_Context::userConf()->apply_only_to_same_feed_entries ? 'checked' : '' ?>>
<?= _t('ext.config.applyOnlyToSameFeedEntries') ?>
</label>
</div>
</div>

Expand Down
20 changes: 14 additions & 6 deletions xExtension-MarkPreviousAsRead/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class MarkPreviousAsReadExtension extends Minz_Extension {
public function init(): void {
$this->registerTranslates();

Minz_View::appendScript($this->getFileUrl('script.js', 'js'), false, true);
Minz_View::appendScript($this->getFileUrl('script.js', 'js'), false, true, false);
Minz_View::appendStyle($this->getFileUrl('style.css', 'css'));

$this->registerHook('js_vars', [$this, 'jsVars']);
Expand All @@ -18,8 +18,13 @@ public function init(): void {
$save = true;
}

if (is_null(FreshRSS_Context::userConf()->apply_to_all_entries_above)) {
FreshRSS_Context::userConf()->apply_to_all_entries_above = false;
if (is_null(FreshRSS_Context::userConf()->apply_only_to_same_feed_entries)) {
if (is_null(FreshRSS_Context::userConf()->apply_to_all_entries_above)) {
FreshRSS_Context::userConf()->apply_only_to_same_feed_entries = false;
} else {
FreshRSS_Context::userConf()->apply_only_to_same_feed_entries = !FreshRSS_Context::userConf()->apply_to_all_entries_above;
}

$save = true;
}

Expand All @@ -31,9 +36,12 @@ public function init(): void {
public function jsVars($vars) {
$vars['markPreviousAsRead']['config'] = [
'enableWarningPopup' => FreshRSS_Context::userConf()->enable_warning_popup,
'applyToAllEntriesAbove' => FreshRSS_Context::userConf()->apply_to_all_entries_above,
'applyOnlyToSameFeedEntries' => FreshRSS_Context::userConf()->apply_only_to_same_feed_entries,
'markAllPreviousAsRead' => Minz_Translate::t('ext.js.markAllPreviousAsRead'),
'markedEntriesAsRead' => Minz_Translate::t('ext.js.markedEntriesAsRead')
'markedEntriesAsRead' => Minz_Translate::t('ext.js.markedEntriesAsRead'),
'warningSameFeed' => Minz_Translate::t('ext.js.warningSameFeed'),
'theSameFeed' => Minz_Translate::t('ext.js.theSameFeed'),
'warning' => Minz_Translate::t('ext.js.warning')
];

return $vars;
Expand All @@ -45,7 +53,7 @@ public function handleConfigureAction(): void {

if (Minz_Request::isPost()) {
FreshRSS_Context::userConf()->enable_warning_popup = Minz_Request::paramString('enable-warning-popup') === '1' ? true : false;
FreshRSS_Context::userConf()->apply_to_all_entries_above = Minz_Request::paramString('apply-to-all-entries-above') === '1' ? true : false;
FreshRSS_Context::userConf()->apply_only_to_same_feed_entries = Minz_Request::paramString('apply-only-to-same-feed-entries') === '1' ? true : false;
FreshRSS_Context::userConf()->save();
}
}
Expand Down
7 changes: 5 additions & 2 deletions xExtension-MarkPreviousAsRead/i18n/en/ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
return [
'config' => [
'enableWarningPopup' => 'Show a validation popup before marking entries as read.',
'applyToAllEntriesAbove' => 'Mark all above entries as read, not only those belonging to the same feed.',
'applyOnlyToSameFeedEntries' => 'Apply only to entries that belong to the same feed.',
'save' => 'Save config',
'cancel' => 'Cancel'
],
'js' => [
'markAllPreviousAsRead' => 'Mark all previous as read',
'markedEntriesAsRead' => 'Marked {0} entries as read'
'markedEntriesAsRead' => 'Marked {0} entries as read',
'warning' => 'Are you sure to mark as read all previous entries?\nThis action cannot be undone.',
'warningSameFeed' => 'Are you sure to mark as read all previous entries that belong to {0}?\nThis action cannot be undone.',
'theSameFeed' => 'the same feed'
]
];
7 changes: 5 additions & 2 deletions xExtension-MarkPreviousAsRead/i18n/fr/ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
return [
'config' => [
'enableWarningPopup' => 'Afficher une confirmation avant de marquer les entrées comme lues.',
'applyToAllEntriesAbove' => 'Appliquer à toutes les entrées précédentes, pas uniquement celles qui appartiennent au même flux.',
'applyOnlyToSameFeedEntries' => 'Appliquer uniquement aux entrées appartenant au même flux.',
'save' => 'Sauvegarder la configuration',
'cancel' => 'Annuler'
],
'js' => [
'markAllPreviousAsRead' => 'Marquer les précédents comme lus',
'markedEntriesAsRead' => 'Marqué {0} entrées comme lues'
'markedEntriesAsRead' => 'Marqué {0} entrées comme lues',
'warning' => 'Êtes-vous sûr(e) de vouloir marquer comme lues toutes les entrées ci-dessus ? Vous ne pourrez plus revenir en arrière.',
'warningSameFeed' => 'Êtes-vous sûr(e) de vouloir marquer comme lues toutes les entrées ci-dessus qui appartiennent à {0} ? Vous ne pourrez plus revenir en arrière.',
'theSameFeed' => 'ce flux'
]
];
4 changes: 2 additions & 2 deletions xExtension-MarkPreviousAsRead/metadata.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "Mark Previous as Read",
"author": "kalvn",
"description": "This extension adds a button in the footer of each entry. Clicking this button will mark all previous entries belonging to the current feed, as read. The goal is, when going through a very long list of entries without reading them all, to be able to stop and continue later.",
"version": "1.1.0",
"description": "This extension adds a button in the footer of each entry. Clicking this button will mark all previous entries as read.",
"version": "1.1.1",
"entrypoint": "MarkPreviousAsRead",
"type": "user"
}
21 changes: 16 additions & 5 deletions xExtension-MarkPreviousAsRead/static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
const iconArrowSvg = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path fill="currentColor" d="M13,20H11V8L5.5,13.5L4.08,12.08L12,4.16L19.92,12.08L18.5,13.5L13,8V20Z" /></svg>';
const iconCheckSvg = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path fill="currentColor" d="M9,20.42L2.79,14.21L5.62,11.38L9,14.77L18.88,4.88L21.71,7.71L9,20.42Z" /></svg>';

function getConfig (key) {
return window.context?.extensions?.markPreviousAsRead?.config?.[key];
}

function t (key) {
return getConfig(key);
}

const addButtonToEachUnprocessedEntry = function () {
document.querySelectorAll('.flux footer > ul:not(.mark-previous-as-read-processed)').forEach(footerList => {
// Create node
Expand All @@ -13,14 +21,17 @@

let fluxName = footerList.closest('.flux').querySelector('.websiteName')?.textContent;

a.innerHTML = iconArrowSvg + context?.extensions?.markPreviousAsRead?.config?.markAllPreviousAsRead;
a.innerHTML = iconArrowSvg + t('markAllPreviousAsRead');
a.setAttribute('href', '#');
a.addEventListener('click', (e) => {
console.log('clicked!');
e.preventDefault();

if (window.context?.extensions?.markPreviousAsRead?.config?.enableWarningPopup) {
if (!confirm(`Are you sure to mark as read all above entries from ${fluxName ?? 'this feed'}?\nThis action cannot be undone.`)) {
const warning = getConfig('applyOnlyToSameFeedEntries')
? t('warningSameFeed').replace('{0}', fluxName ?? t('theSameFeed'))
: t('warning')
if (!confirm(warning)) {
return;
}
}
Expand Down Expand Up @@ -52,7 +63,7 @@
const initialDivLink = div.querySelector('.mark-previous-as-read a');
const idAsString = String(feedId);
while (div) {
if (window.context?.extensions?.markPreviousAsRead?.config?.applyToAllEntriesAbove) {
if (!getConfig('applyOnlyToSameFeedEntries')) {
if (Array.from(div.classList).includes('not_read')) {
mark_read(div, true, true);
count++;
Expand All @@ -66,11 +77,11 @@
}
}

initialDivLink.innerHTML = iconCheckSvg + context?.extensions?.markPreviousAsRead?.config?.markedEntriesAsRead.replace('{0}', count);
initialDivLink.innerHTML = iconCheckSvg + t('markedEntriesAsRead').replace('{0}', count);

// Reset link content after 2 seconds.
setTimeout(function () {
initialDivLink.innerHTML = iconArrowSvg + context?.extensions?.markPreviousAsRead?.config?.markAllPreviousAsRead;
initialDivLink.innerHTML = iconArrowSvg + t('markAllPreviousAsRead');
}, 2000);

div = div.previousElementSibling;
Expand Down
14 changes: 14 additions & 0 deletions xExtension-MarkPreviousAsRead/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,17 @@
.mark-previous-as-read-to-fill {
fill: currentColor;
}

.mark-previous-as-read-settings {
margin-left: 0 !important;
}

.mark-previous-as-read-settings label {
display: flex;
align-items: flex-start;
max-width: 500px;
}

.mark-previous-as-read-settings label input[type="checkbox"] {
margin-right: 10px;
}

0 comments on commit 3eab804

Please sign in to comment.