aboutsummaryrefslogtreecommitdiff
path: root/content_scripts/cs.js
diff options
context:
space:
mode:
Diffstat (limited to 'content_scripts/cs.js')
-rw-r--r--content_scripts/cs.js75
1 files changed, 9 insertions, 66 deletions
diff --git a/content_scripts/cs.js b/content_scripts/cs.js
index e57176b..6b66d92 100644
--- a/content_scripts/cs.js
+++ b/content_scripts/cs.js
@@ -1,86 +1,29 @@
var base_url = undefined
-let formats = ["Atom", "Mrss", "Html"]
-let types = {
- 'application/rss+xml': "rss",
- 'application/atom+xml': "atom",
- 'application/rdf+xml': "rdf",
- 'application/rss': "rss",
- 'application/atom': "atom",
- 'application/rdf': "rdf",
- 'text/rss+xml': "rss",
- 'text/atom+xml': "atom",
- 'text/rdf+xml': "rdf",
- 'text/rss': "rss",
- 'text/atom': "atom",
- 'text/rdf': "rdf"
-}
-
-
-function find_links_in_page() {
- let links = document.querySelectorAll('link[type]');
- let feeds = [];
- for (let i = 0; i < links.length; i++) {
- if (links[i].hasAttribute('type') && links[i].getAttribute('type') in types) {
- let title = links[i].getAttribute('title')
- let href = links[i].getAttribute('href')
- let feed_url = new URL(href, window.location.href).href
- let type = types[links[i].getAttribute('type')]
- let feed = {
- type: `native: ${title || type}`,
- url: feed_url,
- };
- feeds.push(feed);
- }
- }
- return feeds
-}
-
-function get_all_types(feed_url, note) {
- let feeds = [];
- formats.forEach(el => {
- if(note){
- feeds.push({
- type: `rss-bridge (${note}): ${el}`,
- url: feed_url + el
- });
- } else {
- feeds.push({
- type: `rss-bridge: ${el}`,
- url: feed_url + el
- });
- }
- })
- return feeds;
-}
-
-let objs = []
+// Get the list of all feeds, combining bridged and native feeds
async function get_feed_urls() {
let settings = await browser.storage.sync.get("rb");
base_url = settings.rb;
let all_feed_urls = []
- let host = window.location.host;
- for (const obj of objs) {
- for (const obj_host of obj.hosts) {
- if (host.includes(obj_host)) {
- result = await obj.callback()
+ for (const bridge of bridges) {
+ for (const host of bridge.hosts) {
+ if (window.location.host.includes(host)) {
+ result = await bridge.callback()
all_feed_urls = all_feed_urls.concat(result)
break
}
}
}
- all_feed_urls = all_feed_urls.concat(find_links_in_page())
+ all_feed_urls = all_feed_urls.concat(find_feeds_in_page())
return all_feed_urls
}
+// Function to register a new bridge
+let bridges = []
function register(hosts, callback) {
- objs.push({hosts, callback})
+ bridges.push({hosts, callback})
}
-register(["instagram"], get_insta)
-register(["twitter"], get_twitter)
-register(["youtube"], get_youtube)
-
browser.runtime.onMessage.addListener(function (msg, sender) {
return Promise.resolve(get_feed_urls());
})