Skip to content

Commit

Permalink
Add pageRSSLinkToClipboard to copy RSS feed links to clipboard (#480)
Browse files Browse the repository at this point in the history
* feat: add pageRSSLinkToClipboard to copy RSS feed links to clipboard

* feat: allow listing RSS links, add <Any> keyword for copying by index
  • Loading branch information
rafael-xmr authored Jun 11, 2023
1 parent 69f7d57 commit 0c79faa
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
61 changes: 61 additions & 0 deletions app/renderer/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -1237,6 +1296,8 @@ module.exports = {
openLinkExternal,
openNewTab,
openNewTabWithCurrentUrl,
pageRSSLinkToClipboard,
pageRSSLinksList,
pageTitleToClipboard,
pageToClipboard,
pageToClipboardEmacs,
Expand Down
4 changes: 4 additions & 0 deletions app/renderer/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ const defaultBindings = {
"v": {"mapping": "<p.start>"},
"w": {"mapping": "<nextTab>"},
"x": {"mapping": "<openLinkExternal>"},
"yR<Any>": {"mapping": "<pageRSSLinkToClipboard>"},
"yRL": {"mapping": "<pageRSSLinksList>"},
"ye": {"mapping": "<pageToClipboardEmacs>"},
"yf": {"mapping": "<startFollowCopyLink>"},
"yh": {"mapping": "<pageToClipboardHTML>"},
Expand Down Expand Up @@ -1215,6 +1217,8 @@ const uncountableActions = [
"toFirstSplitWindow",
"toLastSplitWindow",
"distrubuteSpaceSplitWindow",
"pageRSSLinkToClipboard",
"pageRSSLinksList",
"pageToClipboard",
"pageTitleToClipboard",
"pageToClipboardEmacs",
Expand Down

0 comments on commit 0c79faa

Please sign in to comment.