aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cs.js43
-rw-r--r--index.js24
-rw-r--r--manifest.json52
-rw-r--r--options.html22
-rw-r--r--options.js20
5 files changed, 128 insertions, 33 deletions
diff --git a/cs.js b/cs.js
index 34f9d79..c3dbedd 100644
--- a/cs.js
+++ b/cs.js
@@ -1,4 +1,4 @@
-let base_url = "https://rb.marks.kitchen"
+var base_url = undefined
let formats = ["Atom", "Mrss", "Html"]
let types = {
'application/rss+xml': "rss",
@@ -56,7 +56,7 @@ 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 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)
@@ -65,13 +65,44 @@ async function get_insta(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)
+ if (match) {
+ 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)
+ }
+ return []
}
+async function get_youtube(url) {
+ let patternUser = /youtube.com\/user\/(\w+).*/
+ let matchUser = url.match(patternUser)
+
+ let patternChannel = /youtube.com\/channel\/(\w+).*/
+ let matchChannel = url.match(patternChannel)
+
+ let patternPlaylist = /youtube.com\/playlist\?list=(\w+)/
+ let matchPlaylist = url.match(patternPlaylist)
+ if (matchUser) {
+ let user = matchUser[1];
+ let feed_url = `${base_url}/?action=display&bridge=Youtube&context=By+username&u=${user}&duration_min=&duration_max=&format=`
+ return get_all_types(feed_url)
+ } else if (matchChannel) {
+ let channelId = matchChannel[1]
+ let feed_url = `${base_url}/?action=display&bridge=Youtube&context=By+channel+id&c=${channelId}&duration_min=&duration_max=&format=`
+ return get_all_types(feed_url)
+ } else if (matchPlaylist) {
+ let playlistId = matchPlaylist[1]
+ let native_url = `https://www.youtube.com/feeds/videos.xml?playlist_id=${playlistId}`
+ let feed_url = `${base_url}/?action=display&bridge=Youtube&context=By+playlist+Id&p=${playlistId}&duration_min=&duration_max=&format=`
+ let rb_feeds = get_all_types(feed_url)
+ return rb_feeds.concat([{ type: `native: Rss`, url: native_url }])
+ }
+ return []
+}
async function get_feed_urls() {
+ let settings = await browser.storage.sync.get("rb");
+ base_url = settings.rb;
let all_feed_urls = []
let url = window.location.href;
//url = url.toLowerCase()
@@ -79,6 +110,8 @@ async function get_feed_urls() {
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))
+ } else if (url.includes("youtube")) {
+ all_feed_urls = all_feed_urls.concat(await get_youtube(url))
}
all_feed_urls = all_feed_urls.concat(find_links_in_page())
return all_feed_urls
diff --git a/index.js b/index.js
index 8a6f81b..9ba390e 100644
--- a/index.js
+++ b/index.js
@@ -1,28 +1,36 @@
-let base_ttrss = "https://fr.marks.kitchen/public.php?op=subscribe&feed_url="
+
+var base_ttrss = undefined
+
function subscribe_link(feed_url){
- return `${base_ttrss}${encodeURIComponent(feed_url)}`;
+ return `${base_ttrss}/public.php?op=subscribe&feed_url=${encodeURIComponent(feed_url)}`;
}
-window.onload = function () {
+window.onload = async function () {
+ let settings = await browser.storage.sync.get("tr");
+ base_ttrss = settings.tr;
let feeds = document.getElementById('feeds');
feeds.innerText = "Loading..."
- console.log(feeds.innerHTML.toString())
browser.tabs.query({ active: true, currentWindow: true }, function (tabs) {
browser.tabs.sendMessage(tabs[0].id, {}).then(
function (feed_urls) {
feeds.innerText = ""
+
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)
+
+ if(base_ttrss){
+ let subLink = document.createElement('a');
+ subLink["href"] = subscribe_link(item.url)
+ subLink.innerText = "subscribe";
+ newDiv.append(subLink)
+ }
+
feeds.append(newDiv)
})
if(feed_urls.length == 0) {
diff --git a/manifest.json b/manifest.json
index 28df413..e19b26a 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,25 +1,37 @@
{
- "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": [
+ "description": "Subscribe to rss feeds with support for rss bridge",
+ "manifest_version": 2,
+ "name": "tt-rss_and_rss-bridge",
+ "version": "1.2",
+ "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"
- ]
-}
+ ],
+ "options_ui": {
+ "page": "options.html"
+ },
+ "browser_specific_settings": {
+ "gecko": {
+ "id": "ttrss_rb@marks.kitchen",
+ "strict_min_version": "42.0"
+ }
+ }
+} \ No newline at end of file
diff --git a/options.html b/options.html
new file mode 100644
index 0000000..236357f
--- /dev/null
+++ b/options.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <meta charset="UTF-8">
+ <title>Options</title>
+</head>
+
+<body>
+ <form>
+ <div>
+ <label>rss-bridge instance<input type="text" id="rb"></label>
+ </div>
+ <div>
+ <label>tt-rss instance<input type="text" id="tr"></label>
+ </div>
+ <button type="submit">Save</button>
+ </form>
+ <script src="options.js"></script>
+</body>
+
+</html> \ No newline at end of file
diff --git a/options.js b/options.js
new file mode 100644
index 0000000..1848954
--- /dev/null
+++ b/options.js
@@ -0,0 +1,20 @@
+function saveOptions(e) {
+ e.preventDefault();
+ browser.storage.sync.set({
+ rb: document.querySelector("#rb").value,
+ tr: document.querySelector("#tr").value
+ });
+}
+function restoreOptions() {
+ function setCurrentChoice(result) {
+ document.querySelector("#rb").value = result.rb || "";
+ document.querySelector("#tr").value = result.tr || "";
+ }
+ function onError(error) {
+ console.log(`Error: ${error}`);
+ }
+ let getting = browser.storage.sync.get(["rb", "tr"]);
+ getting.then(setCurrentChoice, onError);
+}
+document.addEventListener("DOMContentLoaded", restoreOptions);
+document.querySelector("form").addEventListener("submit", saveOptions);