# HG changeset patch # User Guido Berhoerster # Date 1541321677 -3600 # Node ID 086ee559acbb5d11d94227ac103e99310079f49b # Parent 93e4d2b8ae0bb46874063cf3091b5aaba733ef2e Remove unused parameter from xpathQuery and rename functions Remove unused xpathMapping parameter from xpathQuery. Rename xpathQuery to feedQueryXPath, xpathQueryAll to feedQueryXPathAll, and nsMapper to feedNSResolver which better reflects their purpose. diff -r 93e4d2b8ae0b -r 086ee559acbb content_scripts/feed-preview.js --- a/content_scripts/feed-preview.js Thu Oct 04 10:16:49 2018 +0200 +++ b/content_scripts/feed-preview.js Sun Nov 04 09:54:37 2018 +0100 @@ -54,7 +54,7 @@ return (new XMLSerializer()).serializeToString(parsedDocument); } -function nsMapper(prefix) { +function feedNSResolver(prefix) { switch (prefix) { case 'atom': return 'http://www.w3.org/2005/Atom' @@ -64,18 +64,18 @@ return null; } -function xpathQuery(doc, scopeElement, xpathQuery, nsMapping) { - return doc.evaluate(xpathQuery, scopeElement, nsMapper, +function feedQueryXPath(feedDocument, scopeElement, xpathQuery) { + return feedDocument.evaluate(xpathQuery, scopeElement, feedNSResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; } -function xpathQueryAll(doc, scopeElement, xpathQuery, nsMapping) { - let result = doc.evaluate(xpathQuery, scopeElement, nsMapper, +function feedQueryXPathAll(feedDocument, scopeElement, xpathQuery) { + let result = feedDocument.evaluate(xpathQuery, scopeElement, feedNSResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null); let nodes = []; for (let node = result.iterateNext(); node !== null; node = result.iterateNext()) { - nodes.push(node); + nodes.push(node); } return nodes; @@ -90,7 +90,8 @@ class RSS1Logo extends FeedLogo { constructor(feedDocument, imageElement) { - let urlElement = xpathQuery(feedDocument, imageElement, './rss:url'); + let urlElement = feedQueryXPath(feedDocument, imageElement, + './rss:url'); if (urlElement === null) { throw new TypeError('missing element in element'); } @@ -100,7 +101,7 @@ } super(url); - let titleElement = xpathQuery(feedDocument, imageElement, + let titleElement = feedQueryXPath(feedDocument, imageElement, './rss:title'); if (titleElement !== null) { this.title = titleElement.textContent.trim(); @@ -110,7 +111,7 @@ class RSS2Logo extends FeedLogo { constructor(feedDocument, imageElement) { - let urlElement = xpathQuery(feedDocument, imageElement, './url'); + let urlElement = feedQueryXPath(feedDocument, imageElement, './url'); if (urlElement === null) { throw new TypeError('missing element in element'); } @@ -120,7 +121,8 @@ } super(url); - let titleElement = xpathQuery(feedDocument, imageElement, './title'); + let titleElement = feedQueryXPath(feedDocument, imageElement, + './title'); if (titleElement !== null) { this.title = titleElement.textContent.trim(); } @@ -184,12 +186,14 @@ constructor(feedDocument, itemElement) { super(); - let titleElement = xpathQuery(feedDocument, itemElement, './rss:title'); + let titleElement = feedQueryXPath(feedDocument, itemElement, + './rss:title'); if (titleElement !== null) { this.title = titleElement.textContent; } - let linkElement = xpathQuery(feedDocument, itemElement, './rss:link'); + let linkElement = feedQueryXPath(feedDocument, itemElement, + './rss:link'); if (linkElement !== null) { this.url = parseURL(linkElement.textContent); } @@ -200,29 +204,30 @@ constructor(feedDocument, itemElement) { super(); - let titleElement = xpathQuery(feedDocument, itemElement, './title'); + let titleElement = feedQueryXPath(feedDocument, itemElement, './title'); if (titleElement !== null) { this.title = titleElement.textContent; } - let linkElement = xpathQuery(feedDocument, itemElement, './link'); + let linkElement = feedQueryXPath(feedDocument, itemElement, './link'); if (linkElement !== null) { this.url = parseURL(linkElement.textContent); } - let pubDateElement = xpathQuery(feedDocument, itemElement, './pubDate'); + let pubDateElement = feedQueryXPath(feedDocument, itemElement, + './pubDate'); if (pubDateElement !== null) { this.date = parseDate(pubDateElement.textContent); } - let descriptionElement = xpathQuery(feedDocument, itemElement, + let descriptionElement = feedQueryXPath(feedDocument, itemElement, './description'); if (descriptionElement !== null) { this.content = normalizeHTML(descriptionElement.textContent.trim()); } - for (let enclosureElement of xpathQueryAll(feedDocument, itemElement, - './enclosure')) { + for (let enclosureElement of + feedQueryXPathAll(feedDocument, itemElement, './enclosure')) { try { let entryFile = new RSS2EntryFile(enclosureElement); this.files.push(entryFile); @@ -235,28 +240,28 @@ constructor(feedDocument, entryElement) { super(); - let titleElement = xpathQuery(feedDocument, entryElement, + let titleElement = feedQueryXPath(feedDocument, entryElement, './atom:title'); if (titleElement !== null) { this.title = titleElement.textContent.trim(); } - let linkElement = xpathQuery(feedDocument, entryElement, + let linkElement = feedQueryXPath(feedDocument, entryElement, './atom:link[@href][@rel="alternate"]'); if (linkElement !== null) { this.url = parseURL(linkElement.getAttribute('href')); } - let updatedElement = xpathQuery(feedDocument, entryElement, + let updatedElement = feedQueryXPath(feedDocument, entryElement, './atom:updated'); if (updatedElement !== null) { this.date = parseDate(updatedElement.textContent); } - let contentElement = xpathQuery(feedDocument, entryElement, + let contentElement = feedQueryXPath(feedDocument, entryElement, './atom:content'); if (contentElement === null) { - contentElement = xpathQuery(feedDocument, entryElement, + contentElement = feedQueryXPath(feedDocument, entryElement, './atom:summary'); } if (contentElement !== null) { @@ -408,19 +413,19 @@ super(); let documentElement = feedDocument.documentElement; - let titleElement = xpathQuery(feedDocument, documentElement, + let titleElement = feedQueryXPath(feedDocument, documentElement, './rss:channel/rss:title'); if (titleElement !== null) { this.title = titleElement.textContent; } - let descriptionElement = xpathQuery(feedDocument, documentElement, + let descriptionElement = feedQueryXPath(feedDocument, documentElement, './channel/description'); if (descriptionElement !== null) { this.subtitle = descriptionElement.textContent; } - let imageElement = xpathQuery(feedDocument, documentElement, + let imageElement = feedQueryXPath(feedDocument, documentElement, './rss:image'); if (imageElement !== null) { try { @@ -429,7 +434,7 @@ } catch (e) {} } - let itemElements = xpathQueryAll(feedDocument, documentElement, + let itemElements = feedQueryXPathAll(feedDocument, documentElement, './rss:item'); for (let itemElement of itemElements) { let entry = new RSS1Entry(feedDocument, itemElement); @@ -445,19 +450,19 @@ super(); let documentElement = feedDocument.documentElement; - let titleElement = xpathQuery(feedDocument, documentElement, + let titleElement = feedQueryXPath(feedDocument, documentElement, './channel/title'); if (titleElement !== null) { this.title = titleElement.textContent; } - let descriptionElement = xpathQuery(feedDocument, documentElement, + let descriptionElement = feedQueryXPath(feedDocument, documentElement, './channel/description'); if (descriptionElement !== null) { this.subtitle = descriptionElement.textContent; } - let imageElement = xpathQuery(feedDocument, documentElement, + let imageElement = feedQueryXPath(feedDocument, documentElement, './channel/image'); if (imageElement !== null) { try { @@ -466,7 +471,7 @@ } catch (e) {} } - let itemElements = xpathQueryAll(feedDocument, documentElement, + let itemElements = feedQueryXPathAll(feedDocument, documentElement, './channel/item'); for (let itemElement of itemElements) { let entry = new RSS2Entry(feedDocument, itemElement); @@ -482,19 +487,19 @@ super(); let documentElement = feedDocument.documentElement; - let titleElement = xpathQuery(feedDocument, documentElement, + let titleElement = feedQueryXPath(feedDocument, documentElement, './atom:title'); if (titleElement !== null) { this.title = titleElement.textContent.trim(); } - let subtitleElement = xpathQuery(feedDocument, documentElement, + let subtitleElement = feedQueryXPath(feedDocument, documentElement, './atom:subtitle'); if (subtitleElement !== null) { this.subtitle = subtitleElement.textContent.trim(); } - let logoElement = xpathQuery(feedDocument, documentElement, + let logoElement = feedQueryXPath(feedDocument, documentElement, './atom:logo'); if (logoElement !== null) { try { @@ -503,7 +508,7 @@ } catch (e) {} } - let entryElements = xpathQueryAll(feedDocument, documentElement, + let entryElements = feedQueryXPathAll(feedDocument, documentElement, './atom:entry'); for (let entryElement of entryElements) { this.entries.push(new AtomEntry(feedDocument, entryElement));