diff --git a/src/background.ts b/src/background.ts
index d1014f1..c14434e 100644
--- a/src/background.ts
+++ b/src/background.ts
@@ -1,8 +1,8 @@
import browser from 'webextension-polyfill';
browser.webNavigation.onCompleted.addListener(
- async (event: {tabId: string;}) => {
- const { tabId } = event
- await browser.tabs.sendMessage(tabId, {type: 'renderFeed'})
- }
+ async (event: {tabId: string;}) => {
+ const { tabId } = event
+ await browser.tabs.sendMessage(tabId, {type: 'renderFeed'})
+ }
)
diff --git a/src/main.ts b/src/main.ts
index cf784cd..a592cb0 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -136,10 +136,7 @@ const getFeedRoot = () => {
return root
}
-browser.runtime.onMessage.addListener(async (message: {type: Object}) => {
- if (message.type !== 'renderFeed')
- return
-
+const renderFeed = () => {
const xmlDoc = getFeedRoot()
if (!xmlDoc)
// Not an RSS feed
@@ -151,4 +148,33 @@ browser.runtime.onMessage.addListener(async (message: {type: Object}) => {
browser.storage.local.set(parseFeed(channel))
window.location.href = browser.runtime.getURL('viewer/index.html')
+}
+
+const extractFeedUrl = () => {
+ const links = Array.from(document.getElementsByTagName('link'))
+ .filter((link) =>
+ link.getAttribute('rel') === 'alternate' &&
+ link.getAttribute('type') === 'application/rss+xml'
+ )
+
+ if (!links.length)
+ return
+
+ let link = links[0].getAttribute('href') || ''
+ if (link.length && !link.match(/^https?:\/\//)) {
+ let port = window.location.port
+ if (port.length)
+ port = `:${port}`
+ link = `${window.location.protocol}//${window.location.hostname}${port}${link}`
+ }
+
+ return link.length ? link : null
+}
+
+browser.runtime.onMessage.addListener(async (message: {type: Object}) => {
+ if (message.type === 'renderFeed')
+ return renderFeed()
+ if (message.type === 'extractFeedUrl')
+ return extractFeedUrl()
})
+
diff --git a/src/popup/Popup.vue b/src/popup/Popup.vue
index 6fcb0a4..946fe7b 100644
--- a/src/popup/Popup.vue
+++ b/src/popup/Popup.vue
@@ -1,14 +1,34 @@