1
0
mirror of https://github.com/aureliendavid/rsspreview.git synced 2025-08-22 19:28:39 +00:00
This commit is contained in:
Aurelien David 2018-10-29 21:54:28 +01:00
parent a83dad4fe0
commit 282ddf29ea
4 changed files with 30 additions and 194 deletions

View File

@ -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": ["<all_urls>", "webRequest", "webRequestBlocking"]

View File

@ -1,17 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="preview.css">
<!--link rel="shortcut icon" type="image/png" href="icons/rss-48.png"-->
<!--script src="preview.js" ></script-->
</head>
<body>
<div id="feedBody"></div>
</body>
</html>

View File

@ -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<tohtml.length; i++) {
tohtml[i].innerHTML = tohtml[i].innerText;
}
var feed_desc = document.getElementById("feedSubtitleText");
feed_desc.innerHTML = feed_desc.innerText;
}
function removeemptyenclosures() {
var encs = document.getElementsByClassName("enclosures");
for (var i = 0; i<encs.length; i++) {
if (!encs[i].firstChild)
encs[i].style.display = "none";
}
}
function formatfilenames() {
var encfn = document.getElementsByClassName("enclosureFilename");
for (var i = 0; i<encfn.length; i++) {
var url = new URL(encfn[i].innerText);
if (url) {
var fn = url.pathname.split("/").pop();
if (fn != "") {
encfn[i].innerText = fn;
}
}
}
}
function formatfilesizes() {
function humanfilesize(size) {
var i = 0;
if (size && size != "" && size > 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<encsz.length; i++) {
var hsize = humanfilesize(encsz[i].innerText);
if (hsize) {
encsz[i].innerText = hsize;
}
}
}
function addfeedurl(url) {
var h1 = document.getElementById("feedTitleText");
h1.innerHTML += ' :: <a href="'+url+'"><img src="icons/rss-32.png" class="headerIcon" />Feed URL</a>';
}
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;
});
});
}

View File

@ -136,6 +136,34 @@
}
function extensionimages() {
var extimgs = document.getElementsByClassName("extImg");
for (var i = 0; i<extimgs.length; i++) {
extimgs[i].src = chrome.extension.getURL(extimgs[i].attributes['data-src'].nodeValue);
}
}
function makepreviewhtml() {
var doc = document.implementation.createHTMLDocument("");
var feedBody = doc.createElement("div");
feedBody.id = "feedBody";
doc.body.appendChild(feedBody);
var css = doc.createElement('link');
css.setAttribute('rel', 'stylesheet');
css.setAttribute('href', chrome.extension.getURL("preview.css"));
doc.head.appendChild(css);
return doc;
}
function detect() {
var rootNode = document.getRootNode().documentElement;
@ -170,33 +198,6 @@
}
function extensionimages() {
var extimgs = document.getElementsByClassName("extImg");
for (var i = 0; i<extimgs.length; i++) {
extimgs[i].src = chrome.extension.getURL(extimgs[i].attributes['data-src'].nodeValue);
}
}
function makepreviewhtml() {
var doc = document.implementation.createHTMLDocument("");
var feedBody = doc.createElement("div");
feedBody.id = "feedBody";
doc.body.appendChild(feedBody);
var css = doc.createElement('link');
css.setAttribute('rel', 'stylesheet');
css.setAttribute('href', chrome.extension.getURL("preview.css"));
doc.head.appendChild(css);
return doc;
}
function main(feedNode) {
var feed_url = window.location.href;
@ -209,11 +210,6 @@
// replace the content with the preview document
document.replaceChild(document.importNode(preview.documentElement, true), document.documentElement);
window.document = preview;
console.log(preview);
console.log(window.document);
console.log(document);
removeemptyenclosures();
formatdescriptions();