1
0
mirror of https://github.com/aureliendavid/rsspreview.git synced 2025-08-22 19:28:39 +00:00

detect rss feeds from itunes links

This commit is contained in:
Aurelien David 2019-03-10 15:57:12 +01:00
parent 537dfaeb6c
commit f03abbfb84
2 changed files with 50 additions and 9 deletions

View File

@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "RSSPreview",
"version": "3.5",
"version": "3.6",
"author": "Aurelien David",
"homepage_url": "https://github.com/aureliendavid/rsspreview",

View File

@ -340,6 +340,23 @@
let feeds = {};
function registerFeeds(feeds) {
if (Object.keys(feeds).length > 0) {
function handleResponse(message) {
}
function handleError(error) {
//console.log(error);
}
browser.runtime.sendMessage(feeds).then(handleResponse, handleError);
}
}
var async_send = false;
document.querySelectorAll("link[rel='alternate']").forEach( (elem) => {
let type_attr = elem.getAttribute('type');
@ -361,17 +378,41 @@
}
});
if (Object.keys(feeds).length > 0) {
if (document.domain == "itunes.apple.com") {
function handleResponse(message) {
let match = document.URL.match(/id(\d+)/)
if (match) {
let itunesid = match[1];
var xhr = new XMLHttpRequest();
xhr.open('GET', "https://itunes.apple.com/lookup?id="+itunesid+"&entity=podcast");
xhr.onload = function () {
if (xhr.readyState === xhr.DONE) {
if (xhr.status === 200) {
let res = JSON.parse(xhr.responseText);
if ("results" in res) {
let pod = res["results"][0];
let title = pod["collectionName"] || document.title;
let url = pod["feedUrl"];
if (url) {
feeds[url] = title;
}
}
}
}
function handleError(error) {
//console.log(error);
registerFeeds(feeds);
};
async_send = true;
xhr.send();
}
}
browser.runtime.sendMessage(feeds).then(handleResponse, handleError);
}
if (!async_send)
registerFeeds(feeds);
}