diff --git a/CHANGELOG.md b/CHANGELOG.md index 1258884..6adfc99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. @@ -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. diff --git a/README.md b/README.md index 5bfea17..dc554a1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # 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. @@ -7,3 +7,9 @@ The goal is, when going through a very long list of entries without reading them 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. diff --git a/xExtension-MarkPreviousAsRead/configure.phtml b/xExtension-MarkPreviousAsRead/configure.phtml index a2fb67a..55fd2d4 100644 --- a/xExtension-MarkPreviousAsRead/configure.phtml +++ b/xExtension-MarkPreviousAsRead/configure.phtml @@ -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> diff --git a/xExtension-MarkPreviousAsRead/extension.php b/xExtension-MarkPreviousAsRead/extension.php index 3ecc5d9..f32e511 100644 --- a/xExtension-MarkPreviousAsRead/extension.php +++ b/xExtension-MarkPreviousAsRead/extension.php @@ -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']); @@ -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; } @@ -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; @@ -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(); } } diff --git a/xExtension-MarkPreviousAsRead/i18n/en/ext.php b/xExtension-MarkPreviousAsRead/i18n/en/ext.php index 9922544..33785b3 100644 --- a/xExtension-MarkPreviousAsRead/i18n/en/ext.php +++ b/xExtension-MarkPreviousAsRead/i18n/en/ext.php @@ -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' ] ]; diff --git a/xExtension-MarkPreviousAsRead/i18n/fr/ext.php b/xExtension-MarkPreviousAsRead/i18n/fr/ext.php index 5e0dbcd..506e83a 100644 --- a/xExtension-MarkPreviousAsRead/i18n/fr/ext.php +++ b/xExtension-MarkPreviousAsRead/i18n/fr/ext.php @@ -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' ] ]; diff --git a/xExtension-MarkPreviousAsRead/metadata.json b/xExtension-MarkPreviousAsRead/metadata.json index d088ab7..798bc84 100644 --- a/xExtension-MarkPreviousAsRead/metadata.json +++ b/xExtension-MarkPreviousAsRead/metadata.json @@ -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" } diff --git a/xExtension-MarkPreviousAsRead/static/script.js b/xExtension-MarkPreviousAsRead/static/script.js index b256756..e43b0cd 100644 --- a/xExtension-MarkPreviousAsRead/static/script.js +++ b/xExtension-MarkPreviousAsRead/static/script.js @@ -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 @@ -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; } } @@ -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++; @@ -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; diff --git a/xExtension-MarkPreviousAsRead/static/style.css b/xExtension-MarkPreviousAsRead/static/style.css index 3225113..53e1a6c 100644 --- a/xExtension-MarkPreviousAsRead/static/style.css +++ b/xExtension-MarkPreviousAsRead/static/style.css @@ -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; +}