diff --git a/background.js b/background.js index 1354717..67631a6 100644 --- a/background.js +++ b/background.js @@ -39,3 +39,17 @@ browser.webRequest.onHeadersReceived.addListener( { urls: [''], types: ['main_frame'] }, ['blocking', 'responseHeaders'] ); + + +function handleMessage(request, sender, sendResponse) { + + let popup = new URL(browser.runtime.getURL('popup/popup.html')); + popup.searchParams.set('feeds', JSON.stringify(request)); + + browser.pageAction.setPopup( {tabId: sender.tab.id, popup: popup.toString() }); + browser.pageAction.show(sender.tab.id); + + //sendResponse({response: "Response from background script to tab " + sender.tab.url , id: sender.tab.id }); +} + +browser.runtime.onMessage.addListener(handleMessage); diff --git a/icons/rss-gray-19.png b/icons/rss-gray-19.png new file mode 100644 index 0000000..80894c4 Binary files /dev/null and b/icons/rss-gray-19.png differ diff --git a/icons/rss-gray-38.png b/icons/rss-gray-38.png new file mode 100644 index 0000000..fa607f9 Binary files /dev/null and b/icons/rss-gray-38.png differ diff --git a/manifest.json b/manifest.json index fc7b050..5bb74d1 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "RSSPreview", - "version": "2.8", + "version": "3.0", "author": "Aurelien David", "homepage_url": "https://github.com/aureliendavid/rsspreview", @@ -36,12 +36,21 @@ "page": "settings/options.html" }, + "page_action": { + "browser_style": true, + "default_icon": { + "19": "icons/rss-gray-19.png", + "38": "icons/rss-gray-38.png" + }, + "default_title": "Feeds in page" + }, + "applications": { "gecko": { "id": "{7799824a-30fe-4c67-8b3e-7094ea203c94}" } }, - "permissions": ["", "webRequest", "webRequestBlocking", "storage"] + "permissions": ["", "webRequest", "webRequestBlocking", "storage", "tabs"] } diff --git a/popup/popup.html b/popup/popup.html new file mode 100644 index 0000000..84eafac --- /dev/null +++ b/popup/popup.html @@ -0,0 +1,19 @@ + + + + + + + + + + + +
    + +
+ + + + + diff --git a/popup/popup.js b/popup/popup.js new file mode 100644 index 0000000..7f6d6d7 --- /dev/null +++ b/popup/popup.js @@ -0,0 +1,24 @@ +document.addEventListener("DOMContentLoaded", function(event) { + + + const feedList = document.getElementById('feedList'); + + const url = new URL(location.href); + const feeds = JSON.parse(url.searchParams.get('feeds')); + + for (feed_url in feeds) { + if (feeds.hasOwnProperty(feed_url)) { + let li = document.createElement("li"); + let a = document.createElement("a"); + + a.href = feed_url; + a.target = "_blank"; + a.innerText = feeds[feed_url]; + + li.appendChild(a); + feedList.appendChild(li); + } + } + +}); + diff --git a/rsspreview.js b/rsspreview.js index d0bcddf..39440e5 100644 --- a/rsspreview.js +++ b/rsspreview.js @@ -311,4 +311,59 @@ let feedRoot = detect(); if (feedRoot) main(feedRoot); + else { + + function onResult(options) { + if (options.doDetect) + findFeeds(); + } + + function onError(error) { + console.log(`Error: ${error}`); + } + + let getting = browser.storage.sync.get({ + doDetect: false + }); + getting.then(onResult, onError); + } + + + + function findFeeds() { + + let feeds = {}; + + document.querySelectorAll("link[rel='alternate']").forEach( (elem) => { + + let type = elem.getAttribute('type').toLowerCase(); + if (type.includes('rss') || type.includes('atom') || type.includes('feed')) { + + let title = elem.getAttribute('title'); + let url = elem.href; + + if (url) { + + feeds[url] = (title ? title : url); + + //console.log("Feed: " + (title ? (title + " - ") : "") + url); + } + } + }) + + if (Object.keys(feeds).length > 0) { + + function handleResponse(message) { + } + + function handleError(error) { + //console.log(error); + } + + browser.runtime.sendMessage(feeds).then(handleResponse, handleError); + } + + } + + })(); diff --git a/settings/options.html b/settings/options.html index dc57cfd..2bf2fd7 100644 --- a/settings/options.html +++ b/settings/options.html @@ -14,6 +14,7 @@ + diff --git a/settings/options.js b/settings/options.js index 345c1eb..9d88120 100644 --- a/settings/options.js +++ b/settings/options.js @@ -5,7 +5,8 @@ function saveOptions(e) { browser.storage.sync.set({ doThumb: document.querySelector("#doThumb").checked, doMaxWidth: document.querySelector("#doMaxWidth").checked, - valMaxWidth: document.querySelector("#valMaxWidth").value + valMaxWidth: document.querySelector("#valMaxWidth").value, + doDetect: document.querySelector("#doDetect").checked }); } @@ -17,6 +18,7 @@ function restoreOptions() { document.querySelector("#doThumb").checked = result.doThumb; document.querySelector("#doMaxWidth").checked = result.doMaxWidth; document.querySelector("#valMaxWidth").value = result.valMaxWidth; + document.querySelector("#doDetect").checked = result.doDetect; } function onError(error) { @@ -26,7 +28,8 @@ function restoreOptions() { var getting = browser.storage.sync.get({ doThumb: false, doMaxWidth: true, - valMaxWidth: "900px" + valMaxWidth: "900px", + doDetect: false }); getting.then(onResult, onError);