Are you sure you want to go to an external site to donate a monetary value?
WARNING: Some countries laws may supersede the payment processors policy such as the GDPR and PayPal. While it is highly appreciated to donate, please check with your countries privacy and identity laws regarding privacy of information first. Use at your utmost discretion.
Below is a draft utilizing
fetch
.fetch(document.documentURI) .then((response) => { const contentType = response.headers.get('content-type'); if (checkMediaType(contentType)) { return response.text(); } }) .then((data) => { renderFeed(data) })
I've examined the following code, and I haven't found the ease and sensibility of coding with fetch significantly advantageous because of the following reasons:
file
URL.var xmlHTTPRequest, xmlFile, mimeType, isFeed; const mimeArray = [ 'application/atom+xml', 'application/stream+json', 'application/rss+xml', 'application/rdf+xml' ]; fetch(document.documentURI) .then((response) => { const contentType = response.headers.get('content-type'); if (!checkMediaType(contentType)) { throw new TypeError("Page does not seem to be a feed!"); } return response.arrayBuffer(); }) .then((data) => { let decoder = new TextDecoder(document.characterSet); let text = decoder.decode(data); renderFeed(text) }) function checkStatus(response) { if (response.status >= 200 && response.status < 300) { return Promise.resolve(response.responseText) } else { return Promise.reject(new Error(response.statusText)) } } // Check if is of type syndication feed function checkMediaType(mimeType) { if (!mimeType) { mimeType = 'text/plain'; } for (let i = 0; i < mimeArray.length; i++) { if (mimeType.includes(mimeArray[i]) ) { return true; } // Check if is application/xml or text/xml else if (mimeType.includes('/xml') || mimeType.includes('/html')) { const tagArray = ['feed', 'atom:link', 'rss', 'rdf:RDF']; for (let i = 0; i < tagArray.length; i++) { var query = document.getElementsByTagName(tagArray[i]); if (query.length) { return true; } } } // Check if is plain text (XPath only is usable) else if (mimeType.match('text/plain')) { const tagArray = ['<feed', '<atom:link', '<rss', '<rdf:RDF']; for (let i = 0; i < tagArray.length; i++) { query = ['//*[contains(text(), "' + tagArray[i] + '")]']; query = queryByXPath(query); if (query.length) { return true; } } } } } // Begin processing function renderFeed(xmlFile) { var domParser, xmlDocument, xsltProcessor, newDocument, head, style, isRTL, stylesheet_ltr, stylesheet_rtl, insertDocument, removeDocument; xmlFile = xmlFile .trim(); domParser = new DOMParser(); xmlDocument = domParser .parseFromString( xmlFile, 'text/xml' ); xsltProcessor = new XSLTProcessor(); xslFile = '<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns="http://purl.org/rss/1.0/" xmlns:admin="http://webns.net/mvcb/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:atom10="http://www.w3.org/2005/Atom" xmlns:c="http://s.opencalais.com/1/pred/" xmlns:cc="http://web.resource.org/cc/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/" xmlns:dbo="http://dbpedia.org/ontology/" xmlns:dbp="http://dbpedia.org/property/" xmlns:enc="http://purl.oclc.org/net/rss_2.0/enc#" xmlns:fh="http://purl.org/syndication/history/1.0" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:foo="http://purl.org/rss/1.0/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:georss="http://www.georss.org/georss" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:prov="http://www.w3.org/ns/prov#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:sioc="http://rdfs.org/sioc/ns#" xmlns:sioct="http://rdfs.org/sioc/types#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output method="html" indent="yes" omit-xml-decleration="no"/><xsl:output media-type="application/atom+xml"/><xsl:template match="/atom:feed"><xsl:variable name="rtl" select="@xml:lang[ contains(self::node(),"ar") or contains(self::node(),"fa") or contains(self::node(),"he") or contains(self::node(),"ji") or contains(self::node(),"ku") or contains(self::node(),"ur") or contains(self::node(),"yi")]"/><html><head><xsl:call-template name="metadata"><xsl:with-param name="name" select=""description""/><xsl:with-param name="content" select="atom:subtitle"/></xsl:call-template><xsl:call-template name="metadata"><xsl:with-param name="name" select=""generator""/><xsl:with-param name="content" select=""syndication4humans https://sjehuda.github.io/""/></xsl:call-template><xsl:call-template name="metadata"><xsl:with-param name="name" select=""mimetype""/><xsl:with-param name="content" select=""application/atom+xml""/></xsl:call-template><title><xsl:choose><xsl:when test="atom:title and not(atom:title="")"><xsl:value-of select="atom:title"/></xsl:when><xsl:otherwise>Streamburner News Reader</xsl:otherwise></xsl:choose></title><xsl:if test="$rtl"><meta name="semitic" content="true"/></xsl:if></head><body><div id="feed"><header><div id="title"><xsl:choose><xsl:when test="atom:title and not(atom:title="")"><xsl:attribute name="title"><xsl:value-of select="atom:title"/></xsl:attribute><xsl:value-of select="atom:title"/></xsl:when><xsl:otherwise><div class="empty"/></xsl:otherwise></xsl:choose></div><div id="subtitle"><xsl:attribute name="title"><xsl:value-of select="atom:subtitle"/></xsl:attribute><xsl:value-of select="atom:subtitle"/></div></header><section id="links"><a title="Click to get the latest updates and news" onclick="location.href = "feed:" + location.href"></a><a title="Subscribe via SubToMe"><xsl:attribute name="href">https://www.subtome.com/#/subscribe?feeds=<xsl:value-of select="atom:link[@rel="self"]/@href"/></xsl:attribute><xsl:attribute name="onclick">(function(btn){var z=document.createElement("script");document.subtomeBtn=btn;z.src="https://www.subtome.com/load.js";document.body.appendChild(z);})(this);return false;</xsl:attribute></a><a title="Learn about syndication feed" onclick="document.getElementById("aboutfeed").classList.toggle("show");" class="popup"><span class="popuptext" id="aboutfeed"/></a><a href="https://wikiless.org/wiki/Template:Aggregators" title="Get a feed reader for desktop and mobile"/><a href="https://wikiless.org/wiki/RSS" title="Learn the benefits of using feeds for personal and corporates"/></section><xsl:choose><xsl:when test="atom:entry"><div id="toc"><xsl:for-each select="atom:entry[not(position() >20)]"><xsl:if test="atom:title"><xsl:element name="a"><xsl:attribute name="href"><xsl:text>#newspaper-oujs-</xsl:text><xsl:value-of select="position()"/></xsl:attribute><xsl:value-of select="atom:title"/></xsl:element></xsl:if></xsl:for-each></div></xsl:when></xsl:choose><section id="articles"><xsl:choose><xsl:when test="atom:entry"><xsl:for-each select="atom:entry[not(position() >20)]"><div class="entry"><xsl:if test="atom:title"><div class="title"><xsl:element name="a"><xsl:attribute name="href"><xsl:choose><xsl:when test="atom:link[contains(@rel,"alternate")]"><xsl:value-of select="atom:link[contains(@rel,"alternate")]/@href"/></xsl:when><xsl:otherwise><xsl:value-of select="atom:link/@href"/></xsl:otherwise></xsl:choose></xsl:attribute><xsl:attribute name="title"><xsl:value-of select="atom:title"/></xsl:attribute><xsl:attribute name="id"><xsl:text>newspaper-oujs-</xsl:text><xsl:value-of select="position()"/></xsl:attribute><xsl:value-of select="atom:title"/></xsl:element></div></xsl:if><xsl:choose><xsl:when test="geo:lat and geo:long"><xsl:variable name="lat" select="geo:lat"/><xsl:variable name="lng" select="geo:long"/><span class="geolocation"><a href="geo:{$lat},{$lng}">๐</a></span></xsl:when><xsl:when test="geo:Point"><xsl:variable name="lat" select="geo:Point/geo:lat"/><xsl:variable name="lng" select="geo:Point/geo:long"/><span class="geolocation"><a href="geo:{$lat},{$lng}">๐</a></span></xsl:when><xsl:when test="georss:point"><xsl:variable name="lat" select="substring-before(georss:point, " ")"/><xsl:variable name="lng" select="substring-after(georss:point, " ")"/><xsl:variable name="name" select="georss:featurename"/><span class="geolocation"><a href="geo:{$lat},{$lng}" title="{$name}">๐</a></span></xsl:when></xsl:choose><xsl:choose><xsl:when test="atom:updated"><div class="updated"><xsl:value-of select="atom:updated"/></div></xsl:when><xsl:when test="atom:published"><div class="published"><xsl:value-of select="atom:published"/></div></xsl:when><xsl:otherwise><div class="warning atom1 published"/></xsl:otherwise></xsl:choose><xsl:if test="atom:content or atom:summary"><div class="content"><xsl:choose><xsl:when test="atom:summary[contains(@type,"text")]"><xsl:attribute name="type"><xsl:value-of select="atom:summary/@type"/></xsl:attribute><xsl:value-of select="atom:summary"/></xsl:when><xsl:when test="atom:summary[contains(@type,"base64")]"></xsl:when><xsl:when test="atom:content[contains(@type,"text")]"><xsl:attribute name="type"><xsl:value-of select="atom:content/@type"/></xsl:attribute><xsl:value-of select="atom:content"/></xsl:when><xsl:when test="atom:content[contains(@type,"base64")]"></xsl:when><xsl:otherwise><xsl:choose><xsl:when test="atom:summary and not(atom:summary="")"><xsl:value-of select="atom:summary" disable-output-escaping="yes"/></xsl:when><xsl:otherwise><xsl:value-of select="atom:content" disable-output-escaping="yes"/></xsl:otherwise></xsl:choose></xsl:otherwise></xsl:choose></div></xsl:if><xsl:if test="atom:link[contains(@rel,"enclosure")]"><div class="enclosure" title="Right-click and Save link asโฆ"><xsl:for-each select="atom:link[contains(@rel,"enclosure")]"><xsl:element name="span"><xsl:attribute name="icon"><xsl:value-of select="substring-before(@type,"/")"/></xsl:attribute></xsl:element><xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute><xsl:attribute name="download"/><xsl:call-template name="extract-filename"><xsl:with-param name="url" select="@href"/></xsl:call-template></xsl:element><xsl:element name="span"><xsl:attribute name="class"><xsl:value-of select="substring-before(@type,"/")"/></xsl:attribute></xsl:element><xsl:if test="@length > 0"><xsl:call-template name="transform-filesize"><xsl:with-param name="length" select="@length"/></xsl:call-template></xsl:if><xsl:element name="br"/></xsl:for-each><xsl:for-each select="media:content"><xsl:element name="span"><xsl:attribute name="icon"><xsl:value-of select="@medium"/></xsl:attribute></xsl:element><xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="@url"/></xsl:attribute><xsl:attribute name="download"/><xsl:call-template name="extract-filename"><xsl:with-param name="url" select="@url"/></xsl:call-template></xsl:element><xsl:element name="span"><xsl:attribute name="class"><xsl:value-of select="@medium"/></xsl:attribute></xsl:element><xsl:if test="@fileSize > 0"><xsl:call-template name="transform-filesize"><xsl:with-param name="length" select="@fileSize"/></xsl:call-template></xsl:if><xsl:element name="br"/></xsl:for-each></div></xsl:if></div><xsl:if test="not(atom:id)"><div class="warning atom1 id"/></xsl:if></xsl:for-each></xsl:when><xsl:otherwise><div class="notice no-entry"/></xsl:otherwise></xsl:choose></section></div></body></html></xsl:template><xsl:output media-type="application/rdf+xml"/><xsl:template match="/rdf:RDF"><xsl:variable name="rtl" select="channel/language[ contains(text(),"ar") or contains(text(),"fa") or contains(text(),"he") or contains(text(),"ji") or contains(text(),"ku") or contains(text(),"ur") or contains(text(),"yi")]"/><html><head><xsl:call-template name="metadata"><xsl:with-param name="name" select=""description""/><xsl:with-param name="content" select="foo:channel/foo:description"/></xsl:call-template><xsl:call-template name="metadata"><xsl:with-param name="name" select=""generator""/><xsl:with-param name="content" select=""syndication4humans https://sjehuda.github.io/""/></xsl:call-template><xsl:call-template name="metadata"><xsl:with-param name="name" select=""mimetype""/><xsl:with-param name="content" select=""application/rdf+xml""/></xsl:call-template><title><xsl:choose><xsl:when test="foo:channel/foo:title and not(foo:channel/foo:title="")"><xsl:value-of select="foo:channel/foo:title"/></xsl:when><xsl:otherwise>Streamburner News Reader</xsl:otherwise></xsl:choose></title><xsl:if test="$rtl"><meta name="semitic" content="true"/></xsl:if></head><body><div id="feed"><header><div id="title"><xsl:choose><xsl:when test="foo:channel/foo:title and not(foo:channel/foo:title="")"><xsl:attribute name="title"><xsl:value-of select="foo:channel/foo:title"/></xsl:attribute><xsl:value-of select="foo:channel/foo:title"/></xsl:when><xsl:otherwise><div class="empty"/></xsl:otherwise></xsl:choose></div><xsl:choose><xsl:when test="foo:channel/itunes:subtitle"><div id="subtitle"><xsl:attribute name="title"><xsl:value-of select="foo:channel/itunes:subtitle"/></xsl:attribute><xsl:value-of select="foo:channel/itunes:subtitle"/></div></xsl:when><xsl:when test="foo:channel/foo:description"><div id="subtitle"><xsl:attribute name="title"><xsl:value-of select="foo:channel/foo:description"/></xsl:attribute><xsl:value-of select="foo:channel/foo:description"/></div></xsl:when></xsl:choose></header><section id="links"><a title="Click to get the latest updates and news" onclick="location.href = "feed:" + location.href"></a><a title="Subscribe via SubToMe"><xsl:attribute name="href">https://www.subtome.com/#/subscribe?feeds=<xsl:value-of select="atom:link[@rel="self"]/@href"/></xsl:attribute><xsl:attribute name="onclick">(function(btn){var z=document.createElement("script");document.subtomeBtn=btn;z.src="https://www.subtome.com/load.js";document.body.appendChild(z);})(this);return false;</xsl:attribute></a><a title="Learn about syndication feed" onclick="document.getElementById("aboutfeed").classList.toggle("show");" class="popup"><span class="popuptext" id="aboutfeed"/></a><a href="https://wikiless.org/wiki/Template:Aggregators" title="Get a feed reader for desktop and mobile"/><a href="https://wikiless.org/wiki/RSS" title="Learn the benefits of using feeds for personal and corporates"/></section><xsl:choose><xsl:when test="foo:item"><div id="toc"><xsl:for-each select="foo:item[not(position() >20)]"><xsl:choose><xsl:when test="itunes:subtitle"><xsl:element name="a"><xsl:attribute name="href"><xsl:text>#newspaper-oujs-</xsl:text><xsl:value-of select="position()"/></xsl:attribute><xsl:value-of select="itunes:subtitle"/></xsl:element></xsl:when><xsl:when test="foo:title"><xsl:element name="a"><xsl:attribute name="href"><xsl:text>#newspaper-oujs-</xsl:text><xsl:value-of select="position()"/></xsl:attribute><xsl:value-of select="foo:title"/></xsl:element></xsl:when></xsl:choose></xsl:for-each></div></xsl:when></xsl:choose><section id="articles"><xsl:choose><xsl:when test="foo:item"><xsl:for-each select="foo:item[not(position() >20)]"><div class="entry"><xsl:choose><xsl:when test="itunes:subtitle"><div class="title"><xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="foo:link"/></xsl:attribute><xsl:attribute name="title"><xsl:value-of select="itunes:subtitle"/></xsl:attribute><xsl:attribute name="id"><xsl:text>newspaper-oujs-</xsl:text><xsl:value-of select="position()"/></xsl:attribute><xsl:value-of select="itunes:subtitle"/></xsl:element></div></xsl:when><xsl:when test="foo:title"><div class="title"><xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="foo:link"/></xsl:attribute><xsl:attribute name="title"><xsl:value-of select="foo:title"/></xsl:attribute><xsl:attribute name="id"><xsl:text>newspaper-oujs-</xsl:text><xsl:value-of select="position()"/></xsl:attribute><xsl:value-of select="foo:title"/></xsl:element></div></xsl:when><xsl:otherwise><div class="warning rss title"/></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="geo:lat and geo:long"><xsl:variable name="lat" select="geo:lat"/><xsl:variable name="lng" select="geo:long"/><span class="geolocation"><a href="geo:{$lat},{$lng}">๐</a></span></xsl:when><xsl:when test="geo:Point"><xsl:variable name="lat" select="geo:Point/geo:lat"/><xsl:variable name="lng" select="geo:Point/geo:long"/><span class="geolocation"><a href="geo:{$lat},{$lng}">๐</a></span></xsl:when><xsl:when test="georss:point"><xsl:variable name="lat" select="substring-before(georss:point, " ")"/><xsl:variable name="lng" select="substring-after(georss:point, " ")"/><xsl:variable name="name" select="georss:featurename"/><span class="geolocation"><a href="geo:{$lat},{$lng}" title="{$name}">๐</a></span></xsl:when></xsl:choose><xsl:if test="dc:date"><div class="published"><xsl:value-of select="dc:date"/></div></xsl:if><xsl:choose><xsl:when test="content:encoded"><div class="content"><xsl:value-of select="content:encoded" disable-output-escaping="yes"/></div></xsl:when><xsl:when test="foo:description"><div class="content"><xsl:value-of select="foo:description" disable-output-escaping="yes"/></div></xsl:when><xsl:when test="itunes:summary"><div class="content"><xsl:value-of select="itunes:summary" disable-output-escaping="yes"/></div></xsl:when><xsl:otherwise><div class="warning rss description"/></xsl:otherwise></xsl:choose><xsl:if test="enc:enclosure"><div class="enclosure" title="Right-click and Save link asโฆ"><xsl:for-each select="enc:enclosure"><xsl:element name="span"><xsl:attribute name="icon"><xsl:value-of select="substring-before(@enc:type,"/")"/></xsl:attribute></xsl:element><xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:attribute name="download"/><xsl:call-template name="extract-filename"><xsl:with-param name="url" select="@rdf:resource"/></xsl:call-template></xsl:element><xsl:element name="span"><xsl:attribute name="class"><xsl:value-of select="substring-before(@enc:type,"/")"/></xsl:attribute></xsl:element><xsl:if test="@enc:length > 0"><xsl:call-template name="transform-filesize"><xsl:with-param name="length" select="@enc:length"/></xsl:call-template></xsl:if><xsl:element name="br"/></xsl:for-each></div></xsl:if></div></xsl:for-each></xsl:when><xsl:otherwise><div class="notice no-entry"/></xsl:otherwise></xsl:choose></section></div></body></html></xsl:template><xsl:output media-type="application/rss+xml"/><xsl:template match="/rss"><xsl:variable name="rtl" select="channel/language[ contains(text(),"ar") or contains(text(),"fa") or contains(text(),"he") or contains(text(),"ji") or contains(text(),"ku") or contains(text(),"ur") or contains(text(),"yi")]"/><html><head><xsl:call-template name="metadata"><xsl:with-param name="name" select=""description""/><xsl:with-param name="content" select="channel/description"/></xsl:call-template><xsl:call-template name="metadata"><xsl:with-param name="name" select=""generator""/><xsl:with-param name="content" select=""syndication4humans https://sjehuda.github.io/""/></xsl:call-template><xsl:call-template name="metadata"><xsl:with-param name="name" select=""mimetype""/><xsl:with-param name="content" select=""application/rss+xml""/></xsl:call-template><title><xsl:choose><xsl:when test="channel/title and not(channel/title="")"><xsl:value-of select="channel/title"/></xsl:when><xsl:otherwise>Streamburner News Reader</xsl:otherwise></xsl:choose></title><xsl:if test="$rtl"><meta name="semitic" content="true"/></xsl:if></head><body><div id="feed"><header><div id="title"><xsl:choose><xsl:when test="channel/title and not(channel/title="")"><xsl:attribute name="title"><xsl:value-of select="channel/title"/></xsl:attribute><xsl:value-of select="channel/title"/></xsl:when><xsl:otherwise><div class="empty"/></xsl:otherwise></xsl:choose></div><xsl:choose><xsl:when test="channel/itunes:subtitle"><div id="subtitle"><xsl:attribute name="title"><xsl:value-of select="channel/itunes:subtitle"/></xsl:attribute><xsl:value-of select="channel/itunes:subtitle"/></div></xsl:when><xsl:when test="channel/description"><div id="subtitle"><xsl:attribute name="title"><xsl:value-of select="channel/description"/></xsl:attribute><xsl:value-of select="channel/description"/></div></xsl:when></xsl:choose></header><section id="links"><a title="Click to get the latest updates and news" onclick="location.href = "feed:" + location.href"></a><a title="Subscribe via SubToMe"><xsl:attribute name="href">https://www.subtome.com/#/subscribe?feeds=<xsl:value-of select="atom:link[@rel="self"]/@href"/></xsl:attribute><xsl:attribute name="onclick">(function(btn){var z=document.createElement("script");document.subtomeBtn=btn;z.src="https://www.subtome.com/load.js";document.body.appendChild(z);})(this);return false;</xsl:attribute></a><a title="Learn about syndication feed" onclick="document.getElementById("aboutfeed").classList.toggle("show");" class="popup"><span class="popuptext" id="aboutfeed"/></a><a href="https://wikiless.org/wiki/Template:Aggregators" title="Get a feed reader for desktop and mobile"/><a href="https://wikiless.org/wiki/RSS" title="Learn the benefits of using feeds for personal and corporates"/></section><xsl:choose><xsl:when test="channel/item"><div id="toc"><xsl:for-each select="channel/item[not(position() >20)]"><xsl:choose><xsl:when test="itunes:subtitle"><xsl:element name="a"><xsl:attribute name="href"><xsl:text>#newspaper-oujs-</xsl:text><xsl:value-of select="position()"/></xsl:attribute><xsl:value-of select="itunes:subtitle"/></xsl:element></xsl:when><xsl:when test="title"><xsl:element name="a"><xsl:attribute name="href"><xsl:text>#newspaper-oujs-</xsl:text><xsl:value-of select="position()"/></xsl:attribute><xsl:value-of select="title"/></xsl:element></xsl:when></xsl:choose></xsl:for-each></div></xsl:when></xsl:choose><section id="articles"><xsl:choose><xsl:when test="channel/item"><xsl:for-each select="channel/item[not(position() >20)]"><div class="entry"><xsl:choose><xsl:when test="itunes:subtitle"><div class="title"><xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute><xsl:attribute name="title"><xsl:value-of select="itunes:subtitle"/></xsl:attribute><xsl:attribute name="id"><xsl:text>newspaper-oujs-</xsl:text><xsl:value-of select="position()"/></xsl:attribute><xsl:value-of select="itunes:subtitle"/></xsl:element></div></xsl:when><xsl:when test="title"><div class="title"><xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute><xsl:attribute name="title"><xsl:value-of select="title"/></xsl:attribute><xsl:attribute name="id"><xsl:text>newspaper-oujs-</xsl:text><xsl:value-of select="position()"/></xsl:attribute><xsl:value-of select="title"/></xsl:element></div></xsl:when><xsl:otherwise><div class="warning rss2 title"/></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="geo:lat and geo:long"><xsl:variable name="lat" select="geo:lat"/><xsl:variable name="lng" select="geo:long"/><span class="geolocation"><a href="geo:{$lat},{$lng}">๐</a></span></xsl:when><xsl:when test="geo:Point"><xsl:variable name="lat" select="geo:Point/geo:lat"/><xsl:variable name="lng" select="geo:Point/geo:long"/><span class="geolocation"><a href="geo:{$lat},{$lng}">๐</a></span></xsl:when><xsl:when test="georss:point"><xsl:variable name="lat" select="substring-before(georss:point, " ")"/><xsl:variable name="lng" select="substring-after(georss:point, " ")"/><xsl:variable name="name" select="georss:featurename"/><span class="geolocation"><a href="geo:{$lat},{$lng}" title="{$name}">๐</a></span></xsl:when></xsl:choose><xsl:if test="pubDate"><div class="published"><xsl:value-of select="pubDate"/></div></xsl:if><xsl:choose><xsl:when test="content:encoded"><div class="content"><xsl:value-of select="content:encoded" disable-output-escaping="yes"/></div></xsl:when><xsl:when test="description"><div class="content"><xsl:value-of select="description" disable-output-escaping="yes"/></div></xsl:when><xsl:when test="itunes:summary"><div class="content"><xsl:value-of select="itunes:summary" disable-output-escaping="yes"/></div></xsl:when><xsl:otherwise><div class="warning rss2 description"/></xsl:otherwise></xsl:choose><xsl:if test="enclosure or media:content"><div class="enclosure" title="Right-click and Save link asโฆ"><xsl:for-each select="enclosure"><xsl:element name="span"><xsl:attribute name="icon"><xsl:value-of select="substring-before(@type,"/")"/></xsl:attribute></xsl:element><xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="@url"/></xsl:attribute><xsl:attribute name="download"/><xsl:call-template name="extract-filename"><xsl:with-param name="url" select="@url"/></xsl:call-template></xsl:element><xsl:element name="span"><xsl:attribute name="class"><xsl:value-of select="substring-before(@type,"/")"/></xsl:attribute></xsl:element><xsl:if test="@length > 0"><xsl:call-template name="transform-filesize"><xsl:with-param name="length" select="@length"/></xsl:call-template></xsl:if><xsl:element name="br"/></xsl:for-each><xsl:for-each select="media:content"><xsl:element name="span"><xsl:attribute name="icon"><xsl:value-of select="@medium"/></xsl:attribute></xsl:element><xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="@url"/></xsl:attribute><xsl:attribute name="download"/><xsl:call-template name="extract-filename"><xsl:with-param name="url" select="@url"/></xsl:call-template></xsl:element><xsl:element name="span"><xsl:attribute name="class"><xsl:value-of select="@medium"/></xsl:attribute></xsl:element><xsl:if test="@fileSize > 0"><xsl:call-template name="transform-filesize"><xsl:with-param name="length" select="@fileSize"/></xsl:call-template></xsl:if><xsl:element name="br"/></xsl:for-each></div></xsl:if></div></xsl:for-each></xsl:when><xsl:otherwise><div class="notice no-entry"/></xsl:otherwise></xsl:choose></section></div></body></html></xsl:template><xsl:template name="metadata"><xsl:param name="name"/><xsl:param name="content"/><xsl:if test="$content and not($content="")"><xsl:element name="meta"><xsl:attribute name="name"><xsl:value-of select="$name"/></xsl:attribute><xsl:attribute name="content"><xsl:value-of select="$content"/></xsl:attribute></xsl:element></xsl:if></xsl:template><xsl:template name="extract-filename"><xsl:param name="url"/><xsl:choose><xsl:when test="substring($url, string-length($url) - string-length("/") + 1) = "/""><xsl:value-of select="substring-after(substring($url, 1, string-length($url) - 1),"://")"/></xsl:when><xsl:otherwise><xsl:choose><xsl:when test="contains($url,"/") and contains(substring-after($url,"/"),".")"><xsl:call-template name="extract-filename"><xsl:with-param name="url" select="substring-after($url,"/")"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:value-of select="$url"/></xsl:otherwise></xsl:choose></xsl:otherwise></xsl:choose></xsl:template><xsl:template name="transform-filesize"><xsl:param name="length"/><xsl:choose><xsl:when test="$length < 2"><xsl:value-of select="$length"/>Byte</xsl:when><xsl:when test="floor($length div 1024) < 1"><xsl:value-of select="$length"/>Bytes</xsl:when><xsl:when test="floor($length div (1024 * 1024)) < 1"><xsl:value-of select="floor($length div 1024)"/>.<xsl:value-of select="substring($length mod 1024,0,2)"/>KiB</xsl:when><xsl:when test="floor($length div (1024 * 1024 * 1024)) < 1"><xsl:value-of select="floor($length div (1024 * 1024))"/>.<xsl:value-of select="substring($length mod (1024 * 1024),0,2)"/>MiB</xsl:when><xsl:otherwise><xsl:value-of select="floor($length div (1024 * 1024 * 1024))"/>.<xsl:value-of select="substring($length mod (1024 * 1024 * 1024),0,2)"/>GiB</xsl:otherwise></xsl:choose></xsl:template></xsl:stylesheet>'; xsltStylesheet = domParser .parseFromString( xslFile, 'application/xml' // application/xslt+xml or text/xsl are Not Valid ); xsltProcessor .importStylesheet( xsltStylesheet ); newDocument = xsltProcessor .transformToDocument( xmlDocument ); // FIXME // Blocked due to server policy // https://archlinux.org/feeds/packages/ // https://www.openstreetmap.org/traces/rss // https://gultsch.social/@daniel.rss // NOTE // We can use inline style (i.e. style="") // but that would make the code lesser manageable stylesheet_ltr = "html,body{padding:0;margin:0}body{background:WhiteSmoke;color:#333;hyphens:auto}header{margin:0 -1em 1em -1em;margin-bottom:1em;padding:1em 1em 0 1em}#feed{min-width:400px;overflow:auto;position:relative}*{max-width:100%;object-fit:contain;height:auto}#logo{display:inline-block;float:left;overflow:hidden;position:relative;height:60px;width:60px;margin-right:9;padding-top:12}#logo>a>img{margin:auto;max-width:100%;position:absolute;width:5em;bottom:0;right:0;left:0;top:0}#title{font-variant:small-caps;text-align:center}#title{font-weight:bold;margin-bottom:0;overflow:hidden;-webkit-line-clamp:2;white-space:nowrap;margin:0;font-size:2.2em}#title .empty:before{font-variant:small-caps;content:'Streamburner News Dashboard';text-align:center}#subtitle{overflow:hidden;-webkit-line-clamp:2;white-space:wrap;font-weight:bold;font-size:1.5em;text-align:center;font-variant:small-caps}.container{display:flex}#links{border-top:.1em solid;margin:auto;width:50%;text-align:center;direction:ltr}#links>a{padding:10px;text-decoration:none;font-size:70%}#links>a:nth-child(1):after{content:'Follow';cursor:pointer;border-color:grey;border-left-style:solid;border-radius:1px;padding:6px;background:#eee !important}#links>a:nth-child(2):after{content:'SubToMe';cursor:pointer}#links>a:nth-child(3):after{content:'Whatโs This?';cursor:help}#links>a:nth-child(4):after{content:'Get a News Reader'}#links>a:nth-child(5):after{content:'More Info...'}#toc{margin-left:3%;padding:5px}#toc:before{content:'Latest Updates';font-size:76%;font-weight:bold}#toc>a{text-decoration:none;font-size:66%;display:block;padding:5px 0;margin-left:1%}#toc>a:hover{text-decoration:underline}#toc>a:visited{text-decoration:line-through}.popup{position:relative;display:inline-block;cursor:pointer}.popup .popuptext{visibility:hidden;width:160px;color:#fff;border-radius:6px;padding:18px;position:absolute;z-index:1;background-color:#555;position:absolute;right:4%;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);width:50%;text-align:left}.popup .popuptext:after{content:'๐ฐ Web Syndication News Feed \\A\\A ' ' Syndication Feed is a mean for content and media publishers ' 'to reach a wider audience easily. ' ' It allows you to receive information directly without the ' 'going from site to site. \\A\\A ' ' Essentially, a feed is a function that allows โFeed Readersโ ' 'to access multiple websites automatically looking for new ' 'content and then posting the information about new content ' 'and updates to another website, mobile app or desktop software ' 'at the office. \\A\\A ' ' Feeds provide a way for users to keep up with the latest ' 'news, events and package and delivery status information ' 'posted on different websites such as social networks, torrent ' 'indexers or podcasts in one spot.';white-space:pre-wrap;line-height:1.8;font-size:150%}.popup .show{visibility:visible;-webkit-animation:fadeIn 1s;animation:fadeIn 1s}@-webkit-keyframes fadeIn{from{opacity:0}to{opacity:1}}@keyframes fadeIn{from{opacity:0}to{opacity:1}}#articles{justify-content:space-between;max-width:90%;margin:0 auto;padding:10px 0}#articles>*{margin:.5em;white-space:normal;vertical-align:top;margin-bottom:50px}.entry{border-bottom:inset;margin-left:auto;margin-right:auto;overflow:auto;line-height:1.6;font-size:85%;overflow-x:hidden}.entry:hover{background:#f8f9fa}.entry *{max-width:98%}.entry>a{white-space:normal}.title{cursor:pointer;display:inline-block;font-size:110%;font-weight:bold;text-decoration:underline;overflow:visible;text-overflow:ellipsis;white-space:nowrap;font-variant:small-caps}a{color:#333;display:inline-block}.geolocation>a{text-decoration:none;padding-left:6px}.author{font-size:75%;margin:0 auto 0 auto}.author:before{content:'By '}.author:after{content:' / '}.published,.updated{font-size:75%;margin:0 auto 0 auto}.content{margin:15px auto 15px 1%;inline-size:95%;text-indent:3px}.content[type='text']{font-family:monospace}code{overflow:auto;display:block;max-height:300px;border-radius:4px}.enclosure{background:#eee;border:1px solid GrayText;border-radius:4px;clear:both;color:#525c66;cursor:help;direction:ltr;font-size:.8em;margin:5px auto 15px 1%;padding:15px;vertical-align:middle;border:1px solid #aaa;border-radius:.5em;max-width:100%;moz-border-radius:.5em;padding:1em}.enclosure>span:after{content:' (Document file) '}.enclosure>span.executable:after{content:' (Executable file) '}.enclosure>span.image:after{content:' (Image file) '}.enclosure>span.audio:after{content:' (Audio file) '}.enclosure>span.video:after{content:' (Video file) '}.enclosure>span[icon]:after{content:'๐๏ธ';margin:3px}.enclosure>span[icon='executable']:after{content:'๐ฆ๏ธ';margin:3px}.enclosure>span[icon='image']:after{content:'๐ผ๏ธ';margin:3px}.enclosure>span[icon='audio']:after{content:'๐ผ๏ธ';margin:3px}.enclosure>span[icon='video']:after{content:'๐ฝ๏ธ';margin:3px}.notice{text-align:center;display:block;font-size:130%;font-weight:lighter;font-variant-caps:small-caps;font-style:oblique;color:FireBrick}.warning{display:block;font-size:60%;font-weight:bold;color:DarkRed}.no-entry:after{content:'This news feed is empty'}.atom1.author:after{content:'Atom 1.0 Warning: Element </author> is missing'}.atom1.id:after{content:'Atom 1.0 Warning: Element </id> is missing'}.atom1.link:after{content:'Atom 1.0 Warning: Element </link> is missing'}.atom1.published:after{content:'Atom 1.0 Warning: Element </published> is missing'}.atom1.title:after{content:'Atom 1.0 Warning: Element </title> is missing'}.rss2.description:after{content:'RSS 2.0 Warning: Element </description> is missing'}.rss2.link:after{content:'RSS 2.0 Warning: Element </link> is missing'}.rss2.title:after{content:'RSS 2.0 Warning: Element </title> is missing'}abbr,acronym{border-bottom:1px dotted #c30}dt{font-weight:bold}"; stylesheet_rtl = "html,body{text-align:right}#feed{direction:rtl}#logo{float:right;margin-left:9}.geolocation>a{padding-right:6px}.image{float:right;margin-left:40px;margin-right:auto}" style = newDocument.createElement('style'); newDocument.head.append(style); style.type = 'text/css'; // NOTE // Because we use JS, maybe it is better to set direction by // the letters of the initial set of words. var isRTL = newDocument .querySelector( 'meta[name="semitic"]' ); if (isRTL) { style.innerHTML = stylesheet_ltr + stylesheet_rtl; } else { style.innerHTML = stylesheet_ltr; } //var newDoc = document.adoptNode(newDoc.documentElement, true); insertDocument = document .importNode( newDocument .documentElement, true ); removeDocument = document .documentElement; document .replaceChild( insertDocument, removeDocument ); } function queryByXPath(queries) { var result; let i = 0; do { result = document.evaluate( queries[i], document, null, XPathResult.STRING_TYPE); i = i + 1; result = result.stringValue; } while (!result && i < queries.length); return result; }
Conclusion: Examine
Promise
withXMLHttpRequest
.Note: Encoding has to be explicitly mentioned if it isn't UTF-8.
Decoding non-utf8 server responses using the Fetch API
https://schneide.blog/2018/08/08/decoding-non-utf8-server-responses-using-the-fetch-api/
document.inputEncoding
can achieve it.let request = fetch(url) .then(response => response.arrayBuffer()) .then(buffer => { let decoder = new TextDecoder(document.inputEncoding); let text = decoder.decode(buffer); handleText(text); });
and
document.characterSet