addons/firefox-addons/feed-preview

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 Nov 04 09:54:37 2018 +0100 (19 months ago)
parents 93e4d2b8ae0b
children 341a0f4b7ce0
files content_scripts/feed-preview.js
line diff
     1.1 --- a/content_scripts/feed-preview.js	Thu Oct 04 10:16:49 2018 +0200
     1.2 +++ b/content_scripts/feed-preview.js	Sun Nov 04 09:54:37 2018 +0100
     1.3 @@ -54,7 +54,7 @@
     1.4      return (new XMLSerializer()).serializeToString(parsedDocument);
     1.5  }
     1.6  
     1.7 -function nsMapper(prefix) {
     1.8 +function feedNSResolver(prefix) {
     1.9      switch (prefix) {
    1.10          case 'atom':
    1.11              return 'http://www.w3.org/2005/Atom'
    1.12 @@ -64,18 +64,18 @@
    1.13      return null;
    1.14  }
    1.15  
    1.16 -function xpathQuery(doc, scopeElement, xpathQuery, nsMapping) {
    1.17 -    return doc.evaluate(xpathQuery, scopeElement, nsMapper,
    1.18 +function feedQueryXPath(feedDocument, scopeElement, xpathQuery) {
    1.19 +    return feedDocument.evaluate(xpathQuery, scopeElement, feedNSResolver,
    1.20              XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    1.21  }
    1.22  
    1.23 -function xpathQueryAll(doc, scopeElement, xpathQuery, nsMapping) {
    1.24 -    let result = doc.evaluate(xpathQuery, scopeElement, nsMapper,
    1.25 +function feedQueryXPathAll(feedDocument, scopeElement, xpathQuery) {
    1.26 +    let result = feedDocument.evaluate(xpathQuery, scopeElement, feedNSResolver,
    1.27              XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
    1.28      let nodes = [];
    1.29      for (let node = result.iterateNext(); node !== null;
    1.30              node = result.iterateNext()) {
    1.31 -            nodes.push(node);
    1.32 +        nodes.push(node);
    1.33      }
    1.34  
    1.35      return nodes;
    1.36 @@ -90,7 +90,8 @@
    1.37  
    1.38  class RSS1Logo extends FeedLogo {
    1.39      constructor(feedDocument, imageElement) {
    1.40 -        let urlElement = xpathQuery(feedDocument, imageElement, './rss:url');
    1.41 +        let urlElement = feedQueryXPath(feedDocument, imageElement,
    1.42 +                './rss:url');
    1.43          if (urlElement === null) {
    1.44              throw new TypeError('missing <url> element in <logo> element');
    1.45          }
    1.46 @@ -100,7 +101,7 @@
    1.47          }
    1.48          super(url);
    1.49  
    1.50 -        let titleElement = xpathQuery(feedDocument, imageElement,
    1.51 +        let titleElement = feedQueryXPath(feedDocument, imageElement,
    1.52                  './rss:title');
    1.53          if (titleElement !== null) {
    1.54              this.title = titleElement.textContent.trim();
    1.55 @@ -110,7 +111,7 @@
    1.56  
    1.57  class RSS2Logo extends FeedLogo {
    1.58      constructor(feedDocument, imageElement) {
    1.59 -        let urlElement = xpathQuery(feedDocument, imageElement, './url');
    1.60 +        let urlElement = feedQueryXPath(feedDocument, imageElement, './url');
    1.61          if (urlElement === null) {
    1.62              throw new TypeError('missing <url> element in <logo> element');
    1.63          }
    1.64 @@ -120,7 +121,8 @@
    1.65          }
    1.66          super(url);
    1.67  
    1.68 -        let titleElement = xpathQuery(feedDocument, imageElement, './title');
    1.69 +        let titleElement = feedQueryXPath(feedDocument, imageElement,
    1.70 +                './title');
    1.71          if (titleElement !== null) {
    1.72              this.title = titleElement.textContent.trim();
    1.73          }
    1.74 @@ -184,12 +186,14 @@
    1.75      constructor(feedDocument, itemElement) {
    1.76          super();
    1.77  
    1.78 -        let titleElement = xpathQuery(feedDocument, itemElement, './rss:title');
    1.79 +        let titleElement = feedQueryXPath(feedDocument, itemElement,
    1.80 +                './rss:title');
    1.81          if (titleElement !== null) {
    1.82              this.title = titleElement.textContent;
    1.83          }
    1.84  
    1.85 -        let linkElement = xpathQuery(feedDocument, itemElement, './rss:link');
    1.86 +        let linkElement = feedQueryXPath(feedDocument, itemElement,
    1.87 +                './rss:link');
    1.88          if (linkElement !== null) {
    1.89              this.url = parseURL(linkElement.textContent);
    1.90          }
    1.91 @@ -200,29 +204,30 @@
    1.92      constructor(feedDocument, itemElement) {
    1.93          super();
    1.94  
    1.95 -        let titleElement = xpathQuery(feedDocument, itemElement, './title');
    1.96 +        let titleElement = feedQueryXPath(feedDocument, itemElement, './title');
    1.97          if (titleElement !== null) {
    1.98              this.title = titleElement.textContent;
    1.99          }
   1.100  
   1.101 -        let linkElement = xpathQuery(feedDocument, itemElement, './link');
   1.102 +        let linkElement = feedQueryXPath(feedDocument, itemElement, './link');
   1.103          if (linkElement !== null) {
   1.104              this.url = parseURL(linkElement.textContent);
   1.105          }
   1.106  
   1.107 -        let pubDateElement = xpathQuery(feedDocument, itemElement, './pubDate');
   1.108 +        let pubDateElement = feedQueryXPath(feedDocument, itemElement,
   1.109 +                './pubDate');
   1.110          if (pubDateElement !== null) {
   1.111              this.date = parseDate(pubDateElement.textContent);
   1.112          }
   1.113  
   1.114 -        let descriptionElement = xpathQuery(feedDocument, itemElement,
   1.115 +        let descriptionElement = feedQueryXPath(feedDocument, itemElement,
   1.116                  './description');
   1.117          if (descriptionElement !== null) {
   1.118              this.content = normalizeHTML(descriptionElement.textContent.trim());
   1.119          }
   1.120  
   1.121 -        for (let enclosureElement of xpathQueryAll(feedDocument, itemElement,
   1.122 -                './enclosure')) {
   1.123 +        for (let enclosureElement of
   1.124 +                feedQueryXPathAll(feedDocument, itemElement, './enclosure')) {
   1.125              try {
   1.126                  let entryFile = new RSS2EntryFile(enclosureElement);
   1.127                  this.files.push(entryFile);
   1.128 @@ -235,28 +240,28 @@
   1.129      constructor(feedDocument, entryElement) {
   1.130          super();
   1.131  
   1.132 -        let titleElement = xpathQuery(feedDocument, entryElement,
   1.133 +        let titleElement = feedQueryXPath(feedDocument, entryElement,
   1.134                  './atom:title');
   1.135          if (titleElement !== null) {
   1.136              this.title = titleElement.textContent.trim();
   1.137          }
   1.138  
   1.139 -        let linkElement = xpathQuery(feedDocument, entryElement,
   1.140 +        let linkElement = feedQueryXPath(feedDocument, entryElement,
   1.141                  './atom:link[@href][@rel="alternate"]');
   1.142          if (linkElement !== null) {
   1.143              this.url = parseURL(linkElement.getAttribute('href'));
   1.144          }
   1.145  
   1.146 -        let updatedElement = xpathQuery(feedDocument, entryElement,
   1.147 +        let updatedElement = feedQueryXPath(feedDocument, entryElement,
   1.148                  './atom:updated');
   1.149          if (updatedElement !== null) {
   1.150              this.date = parseDate(updatedElement.textContent);
   1.151          }
   1.152  
   1.153 -        let contentElement = xpathQuery(feedDocument, entryElement,
   1.154 +        let contentElement = feedQueryXPath(feedDocument, entryElement,
   1.155                  './atom:content');
   1.156          if (contentElement === null) {
   1.157 -            contentElement = xpathQuery(feedDocument, entryElement,
   1.158 +            contentElement = feedQueryXPath(feedDocument, entryElement,
   1.159                      './atom:summary');
   1.160          }
   1.161          if (contentElement !== null) {
   1.162 @@ -408,19 +413,19 @@
   1.163          super();
   1.164  
   1.165          let documentElement = feedDocument.documentElement;
   1.166 -        let titleElement = xpathQuery(feedDocument, documentElement,
   1.167 +        let titleElement = feedQueryXPath(feedDocument, documentElement,
   1.168                  './rss:channel/rss:title');
   1.169          if (titleElement !== null) {
   1.170              this.title = titleElement.textContent;
   1.171          }
   1.172  
   1.173 -        let descriptionElement = xpathQuery(feedDocument, documentElement,
   1.174 +        let descriptionElement = feedQueryXPath(feedDocument, documentElement,
   1.175                  './channel/description');
   1.176          if (descriptionElement !== null) {
   1.177              this.subtitle = descriptionElement.textContent;
   1.178          }
   1.179  
   1.180 -        let imageElement = xpathQuery(feedDocument, documentElement,
   1.181 +        let imageElement = feedQueryXPath(feedDocument, documentElement,
   1.182                  './rss:image');
   1.183          if (imageElement !== null) {
   1.184              try {
   1.185 @@ -429,7 +434,7 @@
   1.186              } catch (e) {}
   1.187          }
   1.188  
   1.189 -        let itemElements = xpathQueryAll(feedDocument, documentElement,
   1.190 +        let itemElements = feedQueryXPathAll(feedDocument, documentElement,
   1.191                  './rss:item');
   1.192          for (let itemElement of itemElements) {
   1.193              let entry = new RSS1Entry(feedDocument, itemElement);
   1.194 @@ -445,19 +450,19 @@
   1.195          super();
   1.196  
   1.197          let documentElement = feedDocument.documentElement;
   1.198 -        let titleElement = xpathQuery(feedDocument, documentElement,
   1.199 +        let titleElement = feedQueryXPath(feedDocument, documentElement,
   1.200                  './channel/title');
   1.201          if (titleElement !== null) {
   1.202              this.title = titleElement.textContent;
   1.203          }
   1.204  
   1.205 -        let descriptionElement = xpathQuery(feedDocument, documentElement,
   1.206 +        let descriptionElement = feedQueryXPath(feedDocument, documentElement,
   1.207                  './channel/description');
   1.208          if (descriptionElement !== null) {
   1.209              this.subtitle = descriptionElement.textContent;
   1.210          }
   1.211  
   1.212 -        let imageElement = xpathQuery(feedDocument, documentElement,
   1.213 +        let imageElement = feedQueryXPath(feedDocument, documentElement,
   1.214                  './channel/image');
   1.215          if (imageElement !== null) {
   1.216              try {
   1.217 @@ -466,7 +471,7 @@
   1.218              } catch (e) {}
   1.219          }
   1.220  
   1.221 -        let itemElements = xpathQueryAll(feedDocument, documentElement,
   1.222 +        let itemElements = feedQueryXPathAll(feedDocument, documentElement,
   1.223                  './channel/item');
   1.224          for (let itemElement of itemElements) {
   1.225              let entry = new RSS2Entry(feedDocument, itemElement);
   1.226 @@ -482,19 +487,19 @@
   1.227          super();
   1.228  
   1.229          let documentElement = feedDocument.documentElement;
   1.230 -        let titleElement = xpathQuery(feedDocument, documentElement,
   1.231 +        let titleElement = feedQueryXPath(feedDocument, documentElement,
   1.232                  './atom:title');
   1.233          if (titleElement !== null) {
   1.234              this.title = titleElement.textContent.trim();
   1.235          }
   1.236  
   1.237 -        let subtitleElement = xpathQuery(feedDocument, documentElement,
   1.238 +        let subtitleElement = feedQueryXPath(feedDocument, documentElement,
   1.239                  './atom:subtitle');
   1.240          if (subtitleElement !== null) {
   1.241              this.subtitle = subtitleElement.textContent.trim();
   1.242          }
   1.243  
   1.244 -        let logoElement =  xpathQuery(feedDocument, documentElement,
   1.245 +        let logoElement =  feedQueryXPath(feedDocument, documentElement,
   1.246                  './atom:logo');
   1.247          if (logoElement !== null) {
   1.248              try {
   1.249 @@ -503,7 +508,7 @@
   1.250              } catch (e) {}
   1.251          }
   1.252  
   1.253 -        let entryElements = xpathQueryAll(feedDocument, documentElement,
   1.254 +        let entryElements = feedQueryXPathAll(feedDocument, documentElement,
   1.255                  './atom:entry');
   1.256          for (let entryElement of entryElements) {
   1.257              this.entries.push(new AtomEntry(feedDocument, entryElement));