From 282ddf29ea2157e9953ee00b66cd84d0e65d36d0 Mon Sep 17 00:00:00 2001 From: Aurelien David Date: Mon, 29 Oct 2018 21:54:28 +0100 Subject: [PATCH] refactor --- manifest.json | 4 +- preview.html | 17 ------ preview.js | 143 -------------------------------------------------- rsspreview.js | 60 ++++++++++----------- 4 files changed, 30 insertions(+), 194 deletions(-) delete mode 100644 preview.html delete mode 100644 preview.js diff --git a/manifest.json b/manifest.json index 3e9a8a3..88e2704 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "RSSPreview", - "version": "1.3", + "version": "2.0", "author": "Aurelien David", "homepage_url": "https://github.com/aureliendavid/rsspreview", @@ -29,7 +29,7 @@ } ], - "web_accessible_resources": ["preview.html", "preview.js", "preview.css", "rss.xsl", "icons/*.png"], + "web_accessible_resources": ["preview.css", "rss.xsl", "icons/*.png"], "permissions": ["", "webRequest", "webRequestBlocking"] diff --git a/preview.html b/preview.html deleted file mode 100644 index 34155c0..0000000 --- a/preview.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - -
- - - - diff --git a/preview.js b/preview.js deleted file mode 100644 index dbcad8c..0000000 --- a/preview.js +++ /dev/null @@ -1,143 +0,0 @@ - -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; iFeed URL'; -} - -function main() { - - var query_string = location.search.substring(1).split("&"); - var feed_url = decodeURIComponent(query_string[0]); - - xhrxml(feed_url, function(feed_xml) { - - - xhrxml(chrome.extension.getURL("rss.xsl"), function(xsl_xml) { - - applyxsl(feed_xml, xsl_xml, document.getElementById("feedBody")); - - removeemptyenclosures(); - formatdescriptions(); - formatfilenames(); - formatfilesizes(); - addfeedurl(feed_url); - - document.title = "RSSPreview: " + document.getElementById("feedTitleText").innerText; - - - }); - - }); - - - - -} diff --git a/rsspreview.js b/rsspreview.js index 37ae904..2ed5ba2 100644 --- a/rsspreview.js +++ b/rsspreview.js @@ -136,6 +136,34 @@ } + function extensionimages() { + + var extimgs = document.getElementsByClassName("extImg"); + for (var i = 0; i