Skip to content

Commit

Permalink
Create reusable getSubscribeURL function
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpie authored and nt1m committed Oct 29, 2018
1 parent 60e9dff commit 6ea0cd0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ chrome.tabs.onRemoved.addListener(function(tabId) {
delete feedData[tabId];
});

function getSubscribeURL(feedUrl) {
const url = chrome.extension.getURL("pages/subscribe/subscribe.html");
return url + "?" + encodeURIComponent(feedUrl);
}

chrome.webRequest.onHeadersReceived.addListener(details => {
const header = details.responseHeaders.find(header => {
return header.name.toLowerCase() == "content-type";
Expand All @@ -235,10 +240,8 @@ chrome.webRequest.onHeadersReceived.addListener(details => {
// Atom or RSS MIME type, redirect to preview page
const type = header.value.toLowerCase().replace(/^\s+|\s*(?:;.*)?$/g, "");
if (type == "application/rss+xml" || type == "application/atom+xml") {
const url = chrome.extension.getURL("pages/subscribe/subscribe.html") + "?" +
encodeURIComponent(details.url);
return {
redirectUrl: url,
redirectUrl: getSubscribeURL(details.url),
};
}

Expand All @@ -260,8 +263,7 @@ chrome.webRequest.onHeadersReceived.addListener(details => {
let feed = await FeedParser.getFeed(details.url);
if (feed.items.length > 0) {
chrome.tabs.update(details.tabId, {
url: chrome.extension.getURL("pages/subscribe/subscribe.html") + "?" +
encodeURIComponent(details.url),
url: getSubscribeURL(details.url),
loadReplace: true
});
}
Expand Down

0 comments on commit 6ea0cd0

Please sign in to comment.