From 8fe602691d88e40ba88c9773ab560d933ca786a0 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Fri, 9 Sep 2022 22:58:51 +0200 Subject: [PATCH] client: Support opening articles in background tab (Firefox only) Fixes: https://github.com/fossar/selfoss/issues/55 --- NEWS.md | 1 + assets/js/shortcuts.js | 31 +++++++++++++++++---- docs/content/docs/administration/options.md | 6 ++++ src/controllers/About.php | 1 + src/helpers/Configuration.php | 3 ++ 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1b05b0f410..5076161c59 100644 --- a/NEWS.md +++ b/NEWS.md @@ -22,6 +22,7 @@ - Add link from settings page to individual sources and vice versa. ([#1329](https://github.com/fossar/selfoss/pull/1329), [#1340](https://github.com/fossar/selfoss/pull/1340)) - Tag colour can be now changed using keyboard. ([#1335](https://github.com/fossar/selfoss/pull/1335)) - YouTube spout now supports all YouTube URLs that provide feeds. ([#1273](https://github.com/fossar/selfoss/issues/1273)) +- Add `open_in_background_tab` option to try to make v shortcut open articles in a background tab ([does not work in Chromium-based browsers](https://crbug.com/431335)). ([#1354](https://github.com/fossar/selfoss/pull/1354)) - Translations into several new languages were added: - English (United Kingdom): `en-GB` - French (Canada): `fr-CA` diff --git a/assets/js/shortcuts.js b/assets/js/shortcuts.js index 9b93143adb..e38160f556 100644 --- a/assets/js/shortcuts.js +++ b/assets/js/shortcuts.js @@ -143,6 +143,30 @@ function ignoreWhenInteracting(handler) { }; } +/** + * Try to open the selected article using the preferred method. + * @param {number} selected + */ +function openSelectedArticle(selected) { + const link = document.querySelector(`.entry[data-entry-id="${selected}"] .entry-datetime`); + if (selfoss.config.openInBackgroundTab) { + // In Chromium, this will just cause the tab to open in the foreground. + // Appears to be disallowed by the pop-under prevention: + // https://crbug.com/431335 + // https://crbug.com/487919 + const event = new MouseEvent( + 'click', + { + ctrlKey: true, + } + ); + link.dispatchEvent(event); + } else { + // open item in new window + link.click(); + } +} + /** * Set up shortcuts on document. */ @@ -251,8 +275,7 @@ export default function makeShortcuts() { var selected = selfoss.entriesPage.getSelectedEntry(); if (selected !== null) { - const elem = document.querySelector(`.entry[data-entry-id="${selected}"]`); - window.open(elem.querySelector('.entry-datetime').getAttribute('href'), undefined, 'noreferrer'); + openSelectedArticle(selected); } e.preventDefault(); @@ -268,9 +291,7 @@ export default function makeShortcuts() { if (selected !== null) { selfoss.entriesPage.markEntryRead(selected, true); - // open item in new window - const elem = document.querySelector(`.entry[data-entry-id="${selected}"]`); - elem.querySelector('.entry-datetime').click(); + openSelectedArticle(selected); } }), diff --git a/docs/content/docs/administration/options.md b/docs/content/docs/administration/options.md index 2326ae83b8..019c02a1e3 100644 --- a/docs/content/docs/administration/options.md +++ b/docs/content/docs/administration/options.md @@ -157,6 +157,12 @@ set this to `1` to automatically collapse an item when another one is opened. set this to `0` to disable automatic loading of more items when you scroll down. With `1`, a click on a button is required instead. +### `open_in_background_tab` +
+ +set this to `1` to try to make v shortcut open articles in new background tab. This [does not work in Chromium based browsers](https://crbug.com/431335). +
+ ### `language`
diff --git a/src/controllers/About.php b/src/controllers/About.php index d829cede10..f53be5495f 100644 --- a/src/controllers/About.php +++ b/src/controllers/About.php @@ -49,6 +49,7 @@ public function about() { 'autoMarkAsRead' => $this->configuration->autoMarkAsRead, // bool 'autoCollapse' => $this->configuration->autoCollapse, // bool 'autoStreamMore' => $this->configuration->autoStreamMore, // bool + 'openInBackgroundTab' => $this->configuration->openInBackgroundTab, // bool 'loadImagesOnMobile' => $this->configuration->loadImagesOnMobile, // bool 'itemsPerPage' => $this->configuration->itemsPerpage, // int 'unreadOrder' => $this->configuration->unreadOrder, // string diff --git a/src/helpers/Configuration.php b/src/helpers/Configuration.php index 31ab8cfb24..4a8a263136 100644 --- a/src/helpers/Configuration.php +++ b/src/helpers/Configuration.php @@ -119,6 +119,9 @@ class Configuration { /** @var bool */ public $autoStreamMore = true; + /** @var bool */ + public $openInBackgroundTab = false; + /** @var ?string */ public $anonymizer = null;