summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurimas Vinckevicius <aurimas.dev@gmail.com>2014-10-30 15:52:00 -0500
committerAurimas Vinckevicius <aurimas.dev@gmail.com>2014-10-30 15:52:00 -0500
commitb579e54c10c834e831c1257312837bc93e8edf6b (patch)
tree20c360c4e6742c3e8e2800a3746455b13104a655
parent79f344e78b91bd24dcc18ac93c8f6975b258bd74 (diff)
parentd0b274e391602f4c1804e55152292ef80d36a57e (diff)
downloadzotero-translators-b579e54c10c834e831c1257312837bc93e8edf6b.tar.gz
zotero-translators-b579e54c10c834e831c1257312837bc93e8edf6b.zip
Merge pull request #792 from proquest/proquest-ebrary-fix
Fixing ProQuest search, widening ebrary's domain
-rw-r--r--ProQuest.js70
-rw-r--r--ebrary.js6
2 files changed, 51 insertions, 25 deletions
diff --git a/ProQuest.js b/ProQuest.js
index f4839cb..0853200 100644
--- a/ProQuest.js
+++ b/ProQuest.js
@@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
- "lastUpdated": "2014-10-02 17:36:32"
+ "lastUpdated": "2014-10-23 16:56:41"
}
/*
@@ -118,6 +118,33 @@ function fetchEmbeddedPdf(url, item, callback) {
}, callback);
}
+function getSearchResults(doc, detect) {
+ var tabs = doc.getElementsByClassName('tabContent');
+ var root;
+ for (var i = 0; i < tabs.length; i++) {
+ if (tabs[i].offsetHeight) {
+ if (Zotero.isBookmarklet && tabs[i].id != 'allResults-content') return false;
+ root = tabs[i].getElementsByClassName('resultListContainer')[0];
+ break;
+ }
+ }
+
+ if (!root) return false;
+
+ var results = ZU.xpath(root, './/a[contains(@class,"previewTitle") or contains(@class,"resultTitle")]');
+
+ if (detect) {
+ return (results.length > 0 ? true : false);
+ }
+
+ var items = new Array();
+ for(var i=0, n=results.length; i<n; i++) {
+ items[results[i].href] = results[i].textContent;
+ }
+
+ return (items.length > 0 ? items : false);
+}
+
function detectWeb(doc, url) {
initLang(doc, url);
@@ -126,10 +153,8 @@ function detectWeb(doc, url) {
//Check for multiple first
if (url.indexOf('docview') == -1 &&
url.indexOf('pagepdf') == -1) {
- var resultitem = ZU.xpath(doc, '//a[contains(@href, "/docview/")]');
- if (resultitem.length) {
+ if (getSearchResults(doc, true))
return "multiple";
- }
}
var types = getTextValue(doc, ["Source type", "Document type", "Record type"]);
@@ -168,27 +193,28 @@ function doWeb(doc, url, pdfUrl) {
scrape(doc, url, type, pdfUrl);
} else if(type == "multiple") {
// detect web returned multiple
- var results = ZU.xpath(doc, '//a[contains(@class,"previewTitle") or\
- contains(@class,"resultTitle")]');
- // If the above didn't get us titles, try agin with a more liberal xPath
- if (!results.length) {
- results = ZU.xpath(doc, '//a[contains(@href, "/docview/")]');
- }
-
- var items = new Array();
- for(var i=0, n=results.length; i<n; i++) {
- items[results[i].href] = results[i].textContent;
- }
-
- Zotero.selectItems(items, function (items) {
+ Zotero.selectItems(getSearchResults(doc, false), function (items) {
if (!items) return true;
var articles = new Array();
- for (var i in items) {
- ZU.processDocuments(i,
- //call doWeb so that we rerun detectWeb to get type and
- //initialize translations
- function(doc) { doWeb(doc, doc.location.href) });
+ for(var item in items) {
+ articles.push(item);
+ }
+
+ if (articles[0].indexOf("ebraryresults") > -1) {
+ // if the first result is for ebrary, the rest are also ebrary
+ ZU.processDocuments(articles, function(doc) {
+ var translator = Zotero.loadTranslator("web");
+ translator.setTranslator("2abe2519-2f0a-48c0-ad3a-b87b9c059459");
+ translator.setDocument(doc);
+ translator.setHandler("itemDone", function(obj, item) {
+ item.complete();
+ });
+ translator.translate();
+ });
+ }
+ else {
+ ZU.processDocuments(articles, doWeb);
}
});
//pdfUrl should be undefined unless we are calling doWeb from the following
diff --git a/ebrary.js b/ebrary.js
index e7fc833..e8c8206 100644
--- a/ebrary.js
+++ b/ebrary.js
@@ -2,14 +2,14 @@
"translatorID": "2abe2519-2f0a-48c0-ad3a-b87b9c059459",
"label": "ebrary",
"creator": "Sebastian Karcher",
- "target": "^https?://site\\.ebrary\\.com/.+(?:docDetail|search)\\.action\\?",
+ "target": "^https?://site\\.ebrary\\.com/.+(?:docDetail|search|detail)\\.action\\?",
"minVersion": "4.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcv",
- "lastUpdated": "2014-03-17 19:59:24"
+ "lastUpdated": "2014-10-24 09:38:21"
}
/*
@@ -33,7 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
function detectWeb(doc, url) {
- if (url.indexOf("docDetail.action?") != -1) return "book";
+ if (url.indexOf("docDetail.action?") != -1 || url.indexOf("detail.action?") != -1) return "book";
else if (url.indexOf("search.action?") != -1) {
if (ZU.xpathText(doc, '//div[@class="book_info_titlelist"]')) return "multiple";
}