aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Powers <markppowers0@gmail.com>2020-11-21 17:56:53 -0600
committerMark Powers <markppowers0@gmail.com>2020-11-21 17:56:53 -0600
commitf11f68adebf45123adbd0b9889bd40349ef4e7a0 (patch)
treeff6b0b44dc1accc76f2dd19913da34969118bd86
Initial commit
-rw-r--r--LICENSE10
-rw-r--r--README.md3
-rw-r--r--cs.js89
-rw-r--r--icon_128.pngbin0 -> 1995 bytes
-rw-r--r--icon_default.pngbin0 -> 3510 bytes
-rw-r--r--index.js28
-rw-r--r--main.html16
-rw-r--r--manifest.json25
8 files changed, 171 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..33cfebc
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,10 @@
+The MIT License (MIT)
+
+Copyright © 2020 <copyright holders>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..dbd33c8
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+This extension has a popup that will give you the option to select from feeds on a page natively (from the link tag in the head), or with RSS-bridge configured to your liking.
+
+This code is inspired and cloned somewhat from https://github.com/idealclover/Easy-to-RSS/
diff --git a/cs.js b/cs.js
new file mode 100644
index 0000000..34f9d79
--- /dev/null
+++ b/cs.js
@@ -0,0 +1,89 @@
+let base_url = "https://rb.marks.kitchen"
+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 normalize_feed_url(feed_url) {
+ if (feed_url.startsWith('/')) {
+ let url = window.location.href
+ feed_url = url.split('/')[0] + '//' + url.split('/')[2] + feed_url;
+ }
+ return feed_url
+}
+
+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 feed_url = normalize_feed_url(links[i].getAttribute('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) {
+ let feeds = [];
+ formats.forEach(el => {
+ feeds.push({
+ type: `rss-bridge: ${el}`,
+ url: feed_url + el
+ });
+ })
+ return feeds;
+}
+
+async function get_insta(url) {
+ let insta_url = url + "?__a=1"
+ console.log("fetching")
+ let res = await fetch(insta_url);
+ let json = await res.json();
+ let uid = json.graphql.user.id
+ let feed_url = `${base_url}/?action=display&bridge=Instagram&context=Username&u=${uid}&media_type=all&format=`;
+ return get_all_types(feed_url)
+}
+
+function get_twitter(url) {
+ let pattern = /twitter.com\/(\w+).*/
+ let match = url.match(pattern);
+ let twitter_handle = match[1]
+ let feed_url = `${base_url}/?action=display&bridge=Twitter&context=By+username&u=${twitter_handle}&format=`
+ return get_all_types(feed_url)
+}
+
+
+async function get_feed_urls() {
+ let all_feed_urls = []
+ let url = window.location.href;
+ //url = url.toLowerCase()
+ if (url.includes("instagram")) {
+ all_feed_urls = all_feed_urls.concat(await get_insta(url))
+ } else if (url.includes("twitter")) {
+ all_feed_urls = all_feed_urls.concat(get_twitter(url))
+ }
+ all_feed_urls = all_feed_urls.concat(find_links_in_page())
+ return all_feed_urls
+}
+
+browser.runtime.onMessage.addListener(function (msg, sender) {
+ return Promise.resolve(get_feed_urls());
+})
diff --git a/icon_128.png b/icon_128.png
new file mode 100644
index 0000000..a3e973d
--- /dev/null
+++ b/icon_128.png
Binary files differ
diff --git a/icon_default.png b/icon_default.png
new file mode 100644
index 0000000..75ca555
--- /dev/null
+++ b/icon_default.png
Binary files differ
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..978cabc
--- /dev/null
+++ b/index.js
@@ -0,0 +1,28 @@
+let base_ttrss = "https://fr.marks.kitchen/public.php?op=subscribe&feed_url="
+function subscribe_link(feed_url){
+ return `${base_ttrss}${encodeURIComponent(feed_url)}`;
+}
+
+window.onload = function () {
+ browser.tabs.query({ active: true, currentWindow: true }, function (tabs) {
+ browser.tabs.sendMessage(tabs[0].id, {}).then(
+ function (feed_urls) {
+ let feeds = document.getElementById('feeds');
+ // let feed_urls = get_feed_urls()
+ console.log("received ", feed_urls.length)
+ feed_urls.forEach(item => {
+ let newLink = document.createElement('a');
+ newLink["href"] = item.url
+ newLink.innerText = item.type;
+ let subLink = document.createElement('a');
+ subLink["href"] = subscribe_link(item.url)
+ subLink.innerText = "subscribe";
+ let newDiv = document.createElement('div');
+ newDiv.append(newLink)
+ newDiv.append(subLink)
+ feeds.append(newDiv)
+ })
+ });
+ });
+}
+
diff --git a/main.html b/main.html
new file mode 100644
index 0000000..1895055
--- /dev/null
+++ b/main.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <style>
+ div a {
+ margin: 1em;
+ }
+ </style>
+ </head>
+ <body>
+ <h1>RSS Feeds</h1>
+ <div id="feeds"></div>
+ <script src="index.js"></script>
+ </body>
+</html>
diff --git a/manifest.json b/manifest.json
new file mode 100644
index 0000000..28df413
--- /dev/null
+++ b/manifest.json
@@ -0,0 +1,25 @@
+{
+ "description": "Subscribe to rss feeds with support for rss bridge",
+ "manifest_version": 2,
+ "name": "tt-rss_and_rss-bridge",
+ "version": "1.0",
+
+ "content_scripts": [{
+ "matches": ["http://*/*", "https://*/*"],
+ "js":["cs.js"]
+ }],
+
+ "browser_action": {
+ "default_icon": "icon_default.png",
+ "default_title": "manage rss for this page",
+ "default_popup": "main.html"
+ },
+ "permissions": [
+ "http://*/*",
+ "https://*/*",
+ "clipboardWrite",
+ "activeTab",
+ "storage",
+ "tabs"
+ ]
+}