mirror of
https://github.com/miniflux/v2.git
synced 2025-08-11 17:51:01 +00:00
refactor(js): split openOriginalLink()
into smaller functions
This commit is contained in:
parent
5c3be3e74f
commit
f2e34cf07f
1 changed files with 50 additions and 32 deletions
|
@ -556,21 +556,6 @@ function toggleEntryStatus(element, toasting) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Mark the entry as read if it is currently unread.
|
|
||||||
*
|
|
||||||
* @param {Element} element The entry element to mark as read.
|
|
||||||
*/
|
|
||||||
function markEntryAsRead(element) {
|
|
||||||
if (element.classList.contains("item-status-unread")) {
|
|
||||||
element.classList.remove("item-status-unread");
|
|
||||||
element.classList.add("item-status-read");
|
|
||||||
|
|
||||||
const entryID = parseInt(element.dataset.id, 10);
|
|
||||||
updateEntriesStatus([entryID], "read");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the refresh of all feeds.
|
* Handle the refresh of all feeds.
|
||||||
*
|
*
|
||||||
|
@ -725,26 +710,59 @@ function handleFetchOriginalContent() {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function openOriginalLink(openLinkInCurrentTab) {
|
function openOriginalLink(openLinkInCurrentTab) {
|
||||||
const entryLink = document.querySelector(".entry h1 a");
|
if (isEntryView()) {
|
||||||
if (entryLink) {
|
openOriginalLinkFromEntryView(openLinkInCurrentTab);
|
||||||
if (openLinkInCurrentTab) {
|
} else if (isListView()) {
|
||||||
window.location.href = entryLink.getAttribute("href");
|
openOriginalLinkFromListView();
|
||||||
} else {
|
|
||||||
openNewTab(entryLink.getAttribute("href"));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const currentItemOriginalLink = document.querySelector(".current-item :is(a, button)[data-original-link]");
|
/**
|
||||||
if (currentItemOriginalLink) {
|
* Open the original link from entry view.
|
||||||
openNewTab(currentItemOriginalLink.getAttribute("href"));
|
*
|
||||||
|
* @param {boolean} openLinkInCurrentTab - Whether to open the link in the current tab.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function openOriginalLinkFromEntryView(openLinkInCurrentTab) {
|
||||||
|
const entryLink = document.querySelector(".entry h1 a");
|
||||||
|
if (!entryLink) return;
|
||||||
|
|
||||||
const currentItem = document.querySelector(".current-item");
|
const url = entryLink.getAttribute("href");
|
||||||
// If we are not on the list of starred items, move to the next item
|
if (openLinkInCurrentTab) {
|
||||||
if (document.location.href !== document.querySelector(':is(a, button)[data-page=starred]').href) {
|
window.location.href = url;
|
||||||
goToListItem(1);
|
} else {
|
||||||
}
|
openNewTab(url);
|
||||||
markEntryAsRead(currentItem);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open the original link from list view.
|
||||||
|
*
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function openOriginalLinkFromListView() {
|
||||||
|
const currentItem = document.querySelector(".current-item");
|
||||||
|
const originalLink = currentItem?.querySelector(":is(a, button)[data-original-link]");
|
||||||
|
|
||||||
|
if (!currentItem || !originalLink) return;
|
||||||
|
|
||||||
|
// Open the link
|
||||||
|
openNewTab(originalLink.getAttribute("href"));
|
||||||
|
|
||||||
|
// Don't navigate or mark as read on starred page
|
||||||
|
const isStarredPage = document.location.href === document.querySelector(':is(a, button)[data-page=starred]').href;
|
||||||
|
if (isStarredPage) return;
|
||||||
|
|
||||||
|
// Navigate to next item
|
||||||
|
goToListItem(1);
|
||||||
|
|
||||||
|
// Mark as read if currently unread
|
||||||
|
if (currentItem.classList.contains("item-status-unread")) {
|
||||||
|
currentItem.classList.remove("item-status-unread");
|
||||||
|
currentItem.classList.add("item-status-read");
|
||||||
|
|
||||||
|
const entryID = parseInt(currentItem.dataset.id, 10);
|
||||||
|
updateEntriesStatus([entryID], "read");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue