commit cdf84b50eefdae67e71f91edba8cd52f9c2aa2d5 Author: Aurelien David Date: Thu Oct 25 22:03:08 2018 +0200 initial commit diff --git a/background.js b/background.js new file mode 100644 index 0000000..0ff5f1b --- /dev/null +++ b/background.js @@ -0,0 +1,23 @@ + +function detectFeed(event) { + + // force application/rss+xml to text/xml so the browser displays it instead of downloading + + for (var header of event.responseHeaders) { + if (header.name.toLowerCase() == "content-type") { + header.value = header.value.replace(/application\/(rss|atom)\+xml/,'text/xml'); + break; + } + } + + return { + responseHeaders: event.responseHeaders + }; + +} + +browser.webRequest.onHeadersReceived.addListener( + detectFeed, + { urls: [""], types: ["main_frame"] }, + ["blocking", "responseHeaders"] +) diff --git a/icons/file.png b/icons/file.png new file mode 100644 index 0000000..9c4c43a Binary files /dev/null and b/icons/file.png differ diff --git a/icons/rss-48.png b/icons/rss-48.png new file mode 100644 index 0000000..644966a Binary files /dev/null and b/icons/rss-48.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..9b8a67e --- /dev/null +++ b/manifest.json @@ -0,0 +1,29 @@ +{ + + "manifest_version": 2, + "name": "RSSPreview", + "version": "1.0", + + "description": "Preview RSS feeds in browser", + + "icons": { + "48": "icons/rss-48.png" + }, + + "background": { + "scripts": ["background.js"] + }, + + + "content_scripts": [ + { + "matches": [""], + "js": ["rsspreview.js"] + } + ], + + "web_accessible_resources": ["preview.html", "preview.js", "preview.css", "rss.xsl", "icons/file.png"], + + "permissions": ["", "webRequest", "webRequestBlocking"] + +} diff --git a/preview.css b/preview.css new file mode 100644 index 0000000..81488fb --- /dev/null +++ b/preview.css @@ -0,0 +1,116 @@ + + +html { + font: 3mm tahoma,arial,helvetica,sans-serif; + background-color: rgb(240, 240, 240); +} + +body { + margin: 0; + padding: 0 3em; + font: message-box; +} + +h1 { + font-size: 160%; + border-bottom: 2px solid ThreeDLightShadow; + margin: 0 0 .2em 0; +} + +h1 a { + color: inherit; + text-decoration: none; +} + +h1 a:hover { + text-decoration: underline; +} + +h2 { + color: GrayText; + font-size: 110%; + font-weight: normal; + margin: 0 0 .6em 0; +} + +a[href] img { + border: none; +} + +#feedBody { + border: 1px solid THreeDShadow; + padding: 3em; + padding-inline-start: 30px; + margin: 2em auto; + background-color: white; +} + +#feedTitleLink { + float: right; + margin-inline-start: .6em; + margin-inline-end: 0; + margin-top: 0; + margin-bottom: 0; +} + + + +#feedTitleContainer { + margin-inline-start: 0; + margin-inline-end: .6em; + margin-top: 0; + margin-bottom: 0; +} + +#feedTitleImage { + margin-inline-start: .6em; + margin-inline-end: 0; + margin-top: 0; + margin-bottom: 0; + max-width: 300px; + max-height: 150px; +} + +.feedEntryContent { + font-size: 110%; +} + +.link { + color: #0000FF; + text-decoration: underline; + cursor: pointer; +} + +.link:hover:active { + color: #FF0000; +} + +.lastUpdated { + font-size: 85%; + font-weight: normal; +} + +.type-icon { + vertical-align: bottom; + height: 16px; + width: 16px; +} + +.enclosures { + border: 1px solid THreeDShadow; + padding: 1em; + margin: 1em auto; + background-color: rgb(240, 240, 240); +} + +.enclosure { + vertical-align: middle; + margin-left: 2px; +} + +.enclosureIcon { + vertical-align: bottom; + height: 16px; + width: 16px; + margin-right: 3px; +} diff --git a/preview.html b/preview.html new file mode 100644 index 0000000..0f0388d --- /dev/null +++ b/preview.html @@ -0,0 +1,17 @@ + + + + + + + + + + + + +
+ + + + diff --git a/preview.js b/preview.js new file mode 100644 index 0000000..d82cd48 --- /dev/null +++ b/preview.js @@ -0,0 +1,136 @@ + +document.addEventListener('DOMContentLoaded', function () { + main(); +}); + +function getxml(url) { + + var xhttp = new XMLHttpRequest(); + xhttp.open("GET", url, false); + xhttp.send(null); + return xhttp.responseXML; +} + + +function xhrxml(url, cb) { + + var xhr = new XMLHttpRequest(); + xhr.open('GET', url, true); + + xhr.responseType = 'document'; + xhr.overrideMimeType('text/xml'); + + xhr.onload = function () { + if (xhr.readyState === xhr.DONE) { + if (xhr.status === 200) { + cb(xhr.responseXML); + } + } + }; + + xhr.send(null); + +} + +function applyxsl(xmlin, xsl, node) { + + var xsltProcessor = new XSLTProcessor(); + xsltProcessor.importStylesheet(xsl); + + var fragment = xsltProcessor.transformToFragment(xmlin, document); + node.appendChild(fragment); + +} + +function formatdescriptions() { + + // unescapes descriptions to html + + var tohtml = document.getElementsByClassName("feedEntryContent"); + for (var i = 0; i 0) + i = Math.floor( Math.log(size) / Math.log(1024) ); + return ( size / Math.pow(1024, i) ).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]; + }; + + var encsz = document.getElementsByClassName("enclosureSize"); + for (var i = 0; i + + + + + + + + + +
+ + + +
+

+ + + +

+

+ +
+
+ + +
+ + + +
+ +

+ + + + + + + + + + + +
+

+
+ +
+
+ + +
+ + + (, ) +
+ +
+
+ +
+
+ +
+ +
+ +
+ + + + + + +
diff --git a/rsspreview.js b/rsspreview.js new file mode 100644 index 0000000..3056bd2 --- /dev/null +++ b/rsspreview.js @@ -0,0 +1,28 @@ +(function() { + /** + * Check and set a global guard variable. + * If this content script is injected into the same page again, + * it will do nothing next time. + */ + if (window.hasRun) { + console.log("already run"); + return; + } + window.hasRun = true; + + const rootName = document.getRootNode().documentElement.nodeName; + + + if (rootName == "rss" || rootName == "channel" || rootName == "feed") { + + var feed_url = window.location.href; + + var url = "preview.html?" + encodeURIComponent(feed_url); + url = chrome.extension.getURL(url); + + // redirect to preview page with feed url as query string + window.location.replace(url); + + } + +})();