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 @@ - diff --git a/src/popup/index.html b/src/popup/index.html index 112786f..82e4e6b 100644 --- a/src/popup/index.html +++ b/src/popup/index.html @@ -2,7 +2,7 @@ - Popup + RSS Viewer Popup
diff --git a/src/viewer/App.vue b/src/viewer/App.vue index 189f5ec..da5327b 100644 --- a/src/viewer/App.vue +++ b/src/viewer/App.vue @@ -18,7 +18,8 @@
-