From 0c79faa6e00017f35886d95acf4a871592f41353 Mon Sep 17 00:00:00 2001 From: Rafael Saes <76502841+saltrafael@users.noreply.github.com> Date: Sun, 11 Jun 2023 09:51:54 -0300 Subject: [PATCH] Add pageRSSLinkToClipboard to copy RSS feed links to clipboard (#480) * feat: add pageRSSLinkToClipboard to copy RSS feed links to clipboard * feat: allow listing RSS links, add keyword for copying by index --- app/renderer/actions.js | 61 +++++++++++++++++++++++++++++++++++++++++ app/renderer/input.js | 4 +++ 2 files changed, 65 insertions(+) diff --git a/app/renderer/actions.js b/app/renderer/actions.js index a7ca7920..a2c50276 100644 --- a/app/renderer/actions.js +++ b/app/renderer/actions.js @@ -865,6 +865,65 @@ const getPageUrl = () => { return url } +const getPageRSSLinks = async() => { + const feedUrls = await currentPage().executeJavaScript( + ` + Array.from(document.querySelectorAll("link[type]")).map( + link => + [ + "application/rss+xml", + "application/atom+xml", + "application/rdf+xml", + "application/rss", + "application/atom", + "application/rdf", + "text/rss+xml", + "text/atom+xml", + "text/rdf+xml", + "text/rss", + "text/atom", + "text/rdf" + ].includes(link.getAttribute("type")) + && link.getAttribute("href") + ).filter(Boolean) + ` + ) + + + if (feedUrls.length === 0) { + notify("No RSS feeds found on this page", "warn") + return + } + + return feedUrls +} + +const pageRSSLinksList = async() => { + const feedUrls = await getPageRSSLinks() + console.info(feedUrls) + if (!feedUrls) { + return + } + const feedsString = feedUrls.map((url, i) => `${i} - ${url}`).join("\n") + notify(`---- RSS links on the page ----\n${feedsString}`) +} + +const pageRSSLinkToClipboard = async args => { + const {key} = args + if (!key) { + return + } + + const feedUrls = await getPageRSSLinks() + if (!feedUrls) { + return + } + + const feedUrl = feedUrls[!isNaN(key) && Number(key) || 0] + clipboard.writeText(feedUrl) + notify(`RSS feed ${feedUrl} copied to clipboard`, "suc") +} + const pageToClipboard = () => clipboard.writeText(getPageUrl()) const pageTitleToClipboard = () => { @@ -1237,6 +1296,8 @@ module.exports = { openLinkExternal, openNewTab, openNewTabWithCurrentUrl, + pageRSSLinkToClipboard, + pageRSSLinksList, pageTitleToClipboard, pageToClipboard, pageToClipboardEmacs, diff --git a/app/renderer/input.js b/app/renderer/input.js index db9ed0df..f795d873 100644 --- a/app/renderer/input.js +++ b/app/renderer/input.js @@ -309,6 +309,8 @@ const defaultBindings = { "v": {"mapping": ""}, "w": {"mapping": ""}, "x": {"mapping": ""}, + "yR": {"mapping": ""}, + "yRL": {"mapping": ""}, "ye": {"mapping": ""}, "yf": {"mapping": ""}, "yh": {"mapping": ""}, @@ -1215,6 +1217,8 @@ const uncountableActions = [ "toFirstSplitWindow", "toLastSplitWindow", "distrubuteSpaceSplitWindow", + "pageRSSLinkToClipboard", + "pageRSSLinksList", "pageToClipboard", "pageTitleToClipboard", "pageToClipboardEmacs",