diff --git a/chrome/content/zotero/xpcom/feedReader.js b/chrome/content/zotero/xpcom/feedReader.js index 66022bab14..239120015a 100644 --- a/chrome/content/zotero/xpcom/feedReader.js +++ b/chrome/content/zotero/xpcom/feedReader.js @@ -53,16 +53,15 @@ * @method {void} terminate Stops retrieving/parsing the feed. Data parsed up * to this point is still available. */ -Zotero.FeedReader = function(url) { +Zotero.FeedReader = function (url) { if (!url) throw new Error("Feed URL must be supplied"); - this._url = url; this._feedItems = [Zotero.Promise.defer()]; this._feedProcessed = Zotero.Promise.defer(); - + let feedFetched = Zotero.Promise.defer(); - feedFetched.promise.then(function(feed) { + feedFetched.promise.then(function (feed) { let info = {}; info.title = feed.title ? feed.title.plainText() : ''; @@ -93,7 +92,7 @@ Zotero.FeedReader = function(url) { if (issn) info.ISSN = issn; let isbn = Zotero.FeedReader._getFeedField(feed, 'isbn', 'prism') - || Zotero.FeedReader._getFeedField(feed, 'isbn') + || Zotero.FeedReader._getFeedField(feed, 'isbn'); if (isbn) info.ISBN = isbn; let language = Zotero.FeedReader._getFeedField(feed, 'language', 'dc') @@ -105,10 +104,10 @@ Zotero.FeedReader = function(url) { this._feedProperties = info; this._feed = feed; - }.bind(this)).then(function(){ + }.bind(this)).then(function () { let items = this._feed.items; if (items && items.length) { - for (let i=0; i { if (!result.doc) { this.terminate("No Feed"); @@ -156,12 +156,12 @@ Zotero.FeedReader = function(url) { Zotero.debug("FeedReader: Fetching feed from " + feedUrl.spec); - this._channel = Services.io.newChannelFromURI2(feedUrl, null, - Services.scriptSecurityManager.getSystemPrincipal(), null, + this._channel = Services.io.newChannelFromURI2(feedUrl, null, + Services.scriptSecurityManager.getSystemPrincipal(), null, Ci.nsILoadInfo.SEC_NORMAL, Ci.nsIContentPolicy.TYPE_OTHER); this._channel.loadFlags |= Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE; this._channel.asyncOpen(feedProcessor, null); // Sends an HTTP request -} +}; /* * The constructor initiates async feed processing, but _feedProcessed @@ -175,7 +175,7 @@ Zotero.FeedReader.prototype.process = Zotero.Promise.coroutine(function* () { * Terminate feed processing at any given time * @param {String} status Reason for terminating processing */ -Zotero.FeedReader.prototype.terminate = function(status) { +Zotero.FeedReader.prototype.terminate = function (status) { Zotero.debug("FeedReader: Terminating feed reader (" + status + ")"); // Reject feed promise if not resolved yet @@ -203,11 +203,11 @@ Zotero.FeedReader.prototype.terminate = function(status) { }; Zotero.defineProperty(Zotero.FeedReader.prototype, 'feedProperties', { - get: function(){ + get: function () { if (!this._feedProperties) { - throw new Error("Feed has not been resolved yet. Try calling FeedReader#process first") + throw new Error("Feed has not been resolved yet. Try calling FeedReader#process first"); } - return this._feedProperties + return this._feedProperties; } }); @@ -220,18 +220,19 @@ Zotero.defineProperty(Zotero.FeedReader.prototype, 'feedProperties', { * for termination. */ Zotero.defineProperty(Zotero.FeedReader.prototype, 'ItemIterator', { - get: function() { + get: function () { let items = this._feedItems; + // eslint-disable-next-line consistent-this let feedReader = this; - let iterator = function() { + let iterator = function () { if (!feedReader._feedProperties) { - throw new Error("Feed has not been resolved yet. Try calling FeedReader#process first") + throw new Error("Feed has not been resolved yet. Try calling FeedReader#process first"); } this.index = 0; }; - iterator.prototype.next = function() { + iterator.prototype.next = function () { let item = items[this.index++]; return { value: item ? item.promise : null, @@ -239,23 +240,23 @@ Zotero.defineProperty(Zotero.FeedReader.prototype, 'ItemIterator', { }; }; - iterator.prototype.last = function() { - return items[items.length-1]; - } + iterator.prototype.last = function () { + return items[items.length - 1]; + }; return iterator; } -}, {lazy: true}); +}, { lazy: true }); /***************************** * Item processing functions * *****************************/ - + /** * Determine item type based on item data */ -Zotero.FeedReader._guessItemType = function(item) { +Zotero.FeedReader._guessItemType = function (item) { // Default to journalArticle item.itemType = 'journalArticle'; @@ -288,12 +289,12 @@ Zotero.FeedReader._guessItemType = function(item) { /* * Fetch creators from given field of a feed entry */ -Zotero.FeedReader._processCreators = function(feedEntry, field, role) { +Zotero.FeedReader._processCreators = function (feedEntry, field, role) { let names = [], nameStr; try { let personArr = feedEntry[field]; // Seems like this part can throw if there is no author data in the feed - for (let i=0; i 1 - // If only one comma and first part has more than one space, - // it's probably not lastName, firstName + && (other || commas > 1 + // If only one comma and first part has more than one space, + // it's probably not lastName, firstName || (commas == 1 && name.split(/\s*,/)[0].indexOf(' ') != -1) ) ) { // Probably multiple authors listed in a single field nameStr = name; break; // For clarity. personArr.length == 1 anyway - } else { + } + else { names.push(name); } } - } - catch(e) { + } + catch (e) { if (e.result != Components.results.NS_ERROR_FAILURE) throw e; if (field != 'authors') return []; @@ -335,7 +336,7 @@ Zotero.FeedReader._processCreators = function(feedEntry, field, role) { } let creators = []; - for (let i=0; i