aboutsummaryrefslogtreecommitdiff
path: root/popup
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2022-12-29 14:03:57 -0600
committerMark Powers <mark@marks.kitchen>2022-12-29 14:03:57 -0600
commitb5c10718ddeaa8fcac368515ca150705b1a2c5ab (patch)
tree473c6b8197774ed3a29df73821c404381535ccbc /popup
parentff9f53e5673d742d155881a2a29f31ba312dce9c (diff)
Refactor scripts, add table preview
Diffstat (limited to 'popup')
-rw-r--r--popup/index.js123
-rw-r--r--popup/main.html22
2 files changed, 145 insertions, 0 deletions
diff --git a/popup/index.js b/popup/index.js
new file mode 100644
index 0000000..c674f39
--- /dev/null
+++ b/popup/index.js
@@ -0,0 +1,123 @@
+var base_reader = undefined
+
+function subscribe_link(reader, feed_url){
+ if(reader == "ttrss"){
+ return `${base_reader}/public.php?op=subscribe&feed_url=${encodeURIComponent(feed_url)}`;
+ } else {
+ return `${base_reader}/bookmarklet?uri=${encodeURIComponent(feed_url)}`;
+ }
+}
+
+window.onload = async function () {
+ let settings = await browser.storage.sync.get(["rb", "reader", "instance"]);
+ base_reader = settings.instance;
+ let base_rb = settings.rb;
+ let feeds = document.getElementById('feeds');
+ feeds.innerText = "Loading..."
+ browser.tabs.query({ active: true, currentWindow: true }, function (tabs) {
+ browser.tabs.sendMessage(tabs[0].id, {}).then(
+ function (feed_urls) {
+ feeds.innerText = ""
+ if(!base_rb) {
+ let newSettingsLink = document.createElement("a")
+ newSettingsLink["href"] = "/options.html"
+ newSettingsLink.innerText = "RSS-bridge instance not set! Click here to open options.";
+ let newDiv = document.createElement('div');
+ newDiv.append(newSettingsLink);
+ feeds.appendChild(newDiv);
+
+ let newP = document.createElement('p')
+ newP.innerText = `Found ${feed_urls.length} feeds`
+ feeds.append(newP)
+ return;
+ }
+
+ feed_urls.forEach(item => {
+ let newLink = document.createElement('a');
+ newLink["href"] = item.url
+ newLink.innerText = item.type;
+
+
+ let newDiv = document.createElement('div');
+ newDiv.append(newLink)
+
+ let previewLink = document.createElement('a');
+ previewLink["onclick"] = function(){
+ fetch(item.url)
+ .then( r => r.text() )
+ .then(r => new window.DOMParser().parseFromString(r, "text/xml"))
+ .then(p => {
+ let channelTitle = "Items"
+ let description = undefined
+ let items = []
+ let lastBuild = undefined
+ console.log(p.firstChild.children)
+ for(const channel of p.firstChild.children) {
+ //p.firstChild.children.forEach(channel => {
+ for(const child of channel.children) {
+ //channel.children.forEach(child => {
+ if(child.tagName == "title"){
+ channelTitle = child.textContent
+ } else if (child.tagName == "lastBuildDate") {
+ lastBuild = child.textContent
+ } else if (child.tagName == "description") {
+ description = child.textContent
+ } else if (child.tagName == "item") {
+ item = {}
+ for(const c of child.children){
+ //child.children.forEach(c => {
+ item[c.tagName] = c.innerHTML
+ }
+ items.push(item)
+ }
+ }
+ }
+ console.log(items)
+ let tableEl = document.createElement("table")
+ items.forEach(item => {
+ let trEl = document.createElement("tr")
+ tableEl.append(trEl)
+
+ let tdEl = document.createElement("td")
+
+ let titleEl = document.createElement("a")
+ titleEl.href = item["link"]
+ titleEl.innerText = item["title"]
+ let wrapperDiv = document.createElement("div")
+ wrapperDiv.append(titleEl)
+ let wrapperDiv2 = document.createElement("div")
+ wrapperDiv2.innerText = item["pubDate"]
+ tdEl.append(wrapperDiv)
+ tdEl.append(wrapperDiv2)
+ trEl.append(tdEl)
+
+ let td3El = document.createElement("td")
+ td3El.innerHTML = item["description"]
+ trEl.append(td3El)
+
+ })
+ feeds.append(tableEl)
+ })
+ }
+ previewLink["href"] = "#"
+ previewLink.innerText = "preview";
+ newDiv.append(previewLink)
+
+ if(base_reader){
+ let subLink = document.createElement('a');
+ subLink["href"] = subscribe_link(settings.reader, item.url)
+ subLink.innerText = "subscribe";
+ newDiv.append(subLink)
+ }
+
+ feeds.append(newDiv)
+ })
+ if(feed_urls.length == 0) {
+ let newP = document.createElement('p')
+ newP.innerText = "No feeds found"
+ feeds.append(newP)
+ }
+ });
+ });
+}
+
diff --git a/popup/main.html b/popup/main.html
new file mode 100644
index 0000000..81f8f06
--- /dev/null
+++ b/popup/main.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <style>
+ div a {
+ margin: 1em;
+ }
+ table td a {
+ margin: 0em;
+ }
+ td {
+ border: 1px solid black;
+ }
+ </style>
+ </head>
+ <body>
+ <h1>RSS Feeds</h1>
+ <div id="feeds"></div>
+ <script src="index.js"></script>
+ </body>
+</html>