From c562d145ec5faf096db9a0f2c8c6f9b4aedef935 Mon Sep 17 00:00:00 2001 From: Matt Burton Date: Mon, 1 Jun 2009 04:30:27 +0000 Subject: [PATCH] Fixes #1478, tweaked xpath and added logic to catch empty selectItems arrays. --- translators/ScienceDirect.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/translators/ScienceDirect.js b/translators/ScienceDirect.js index 61d4bde3b..a4fe89e07 100644 --- a/translators/ScienceDirect.js +++ b/translators/ScienceDirect.js @@ -37,7 +37,7 @@ function doWeb(doc, url) { var xpath; if (url.indexOf("_ob=PublicationURL") != -1) { // not sure if this case still arises. may need to be fixed at some point - xpath = '//table[@class="txt"]/tbody/tr/td[2]'; + xpath = '//table[@class="resultRow"]/tbody/tr/td[2]/a'; } else { xpath = '//div[@class="font3"][@id="bodyMainResults"]/table/tbody/tr/td[2]/a'; } @@ -55,6 +55,10 @@ function doWeb(doc, url) { } else { articles = [url]; } + if(articles.length == 0) { + Zotero.debug('no items'); + return; + } Zotero.Utilities.processDocuments(articles, function(newDoc) { var doi = newDoc.evaluate('//div[@class="articleHeaderInner"][@id="articleHeader"]/a[contains(text(), "doi")]', newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent.substr(4); @@ -123,7 +127,7 @@ function doWeb(doc, url) { if (detectWeb(doc, url) == "multiple") { var items = new Object(); if (url.indexOf("_ob=PublicationURL") != -1) { - xpath = '//table[@class="txt"]/tbody/tr[1]/td[2]'; + xpath = '//table[@class="resultRow"]/tbody/tr/td[2]/a'; // not sure whether this case still exists } else { xpath = '//div[@class="font3"][@id="bodyMainResults"]/table/tbody/tr/td[2]/a'; @@ -133,7 +137,7 @@ function doWeb(doc, url) { while (next_row = rows.iterateNext()) { var title = next_row.textContent; var link = next_row.href; - items[link] = title; + if (!title.match(/PDF \(/) && !title.match(/Related Articles/)) items[link] = title; } items = Zotero.selectItems(items); for (var i in items) { @@ -142,6 +146,10 @@ function doWeb(doc, url) { } else { articles = [url]; } + if(articles.length == 0) { + Zotero.debug('no items'); + return; + } Zotero.Utilities.processDocuments(articles, function(doc2) { var item = new Zotero.Item("journalArticle"); item.repository = "ScienceDirect";