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) 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) } }); }); }