changeset 4:086ee559acbb

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.
author Guido Berhoerster <guido+feed-preview@berhoerster.name>
date Sun, 04 Nov 2018 09:54:37 +0100
parents 93e4d2b8ae0b
children 341a0f4b7ce0
files content_scripts/feed-preview.js
diffstat 1 files changed, 40 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- 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 <url> element in <logo> 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 <url> element in <logo> 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));