www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 9f3f0f12504f82d3eeb7e56dcedf892996844c73
parent bb0d70a050fd8aec9c5c4ec78dd6848235f7b07c
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon,  2 Nov 2009 20:30:23 +0000

Fixed and pushed Informaworld


Diffstat:
Mtranslators/Informaworld.js | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 60 insertions(+), 23 deletions(-)

diff --git a/translators/Informaworld.js b/translators/Informaworld.js @@ -8,7 +8,7 @@ "maxVersion":"", "priority":100, "inRepository":true, - "lastUpdated":"2009-01-08 08:19:07" + "lastUpdated":"2009-11-02 20:30:00" } function detectWeb(doc, url) { @@ -36,7 +36,26 @@ function detectWeb(doc, url) { function doWeb(doc, url) { - var links = new Array(); + // Scrape some data from page + var getDocumentData = function (newDoc, data) { + var xpath = '//div[@id="metahead"]/div'; + var stuff = newDoc.evaluate(xpath, newDoc, null, XPathResult.ANY_TYPE, null); + var thing = stuff.iterateNext(); + while (thing) { + if (thing.textContent.match(/DOI/)) { + data.doi = Zotero.Utilities.trimInternal(thing.textContent).match(/:\s+(.*)/)[1]; + break; + } + thing = stuff.iterateNext(); + } + data.pdfurl = newDoc.evaluate('//div[@id="content"]/div/a[1]', newDoc, null, XPathResult.ANY_TYPE, null).iterateNext().href; + var id = newDoc.location.href.match(/content=([\w\d]+)/); + var post = 'tab=citation&selecteditems=' + id[1].substr(1) + '&content=' + id[1] + '&citstyle=refworks&showabs=false&format=file'; + data.postdata = post; + } + + + var sets = []; if (detectWeb(doc, url) == "multiple") { var items = new Object(); if (doc.evaluate('//div[@id="quicksearch"]//tr/td/b/a', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) { @@ -56,27 +75,40 @@ function doWeb(doc, url) { } items = Zotero.selectItems(items); for (var i in items) { - links.push(i); + sets.push({ url: i }); } } else { - links = [url]; + // If we're on the citation page, get back to the article page, which has the PDF link + var newurl = url.replace('~tab=citation', '~tab=content'); + // If we're already on the main page, just pull out data here + if (newurl == url) { + sets[0] = {}; + getDocumentData(doc, sets[0]); + // Dummy first callback, since we already have the data + var first = function (set, next) { + next(); + }; + } + else { + sets.push({ + url: newurl + }); + } } - Zotero.debug(links); - Zotero.Utilities.processDocuments(links, function(newDoc) { - var xpath = '//div[@id="metahead"]/div'; - var stuff = newDoc.evaluate(xpath, newDoc, null, XPathResult.ANY_TYPE, null); - var thing = stuff.iterateNext() ; - while (thing) { - if (thing.textContent.match(/DOI/)) { - var doi = Zotero.Utilities.trimInternal(thing.textContent).match(/:\s+(.*)/)[1]; - } - thing = stuff.iterateNext(); - } - var pdfurl = newDoc.evaluate('//div[@id="content"]/div/a[1]', newDoc, null, XPathResult.ANY_TYPE, null).iterateNext().href; - var id = newDoc.location.href.match(/content=([\w\d]+)/); - var post = 'tab=citation&selecteditems=' + id[1].substr(1) + '&content=' + id[1] + '&citstyle=refworks&showabs=false&format=file'; - Zotero.Utilities.HTTP.doPost('http://www.informaworld.com/smpp/content', post, function(text) { + if (!first) { + var first = function (set, next) { + var url = set.url; + Zotero.Utilities.processDocuments(url, function(newDoc) { + getDocumentData(newDoc, set); + next(); + }); + }; + } + + var second = function (set, next) { + Zotero.Utilities.HTTP.doPost('http://www.informaworld.com/smpp/content', set.postdata, function(text) { + Zotero.debug(text); text = text.replace(/RT/, "TY"); text = text.replace(/VO/, "VL"); text = text.replace(/LK/, "UR"); @@ -94,14 +126,19 @@ function doWeb(doc, url) { } else if (type == "Book, Section") { item.itemType = "bookSection"; } - if (doi) { - item.DOI = doi; + if (set.doi) { + item.DOI = set.doi; } - item.attachments.push({url:pdfurl, title:item.title, mimeType:'application/pdf'}); + item.attachments.push({url:set.pdfurl, title:item.title, mimeType:'application/pdf'}); item.complete(); }); translator.translate(); + next(); }); - }, function() {Zotero.done();}); + } + + var callbacks = [first, second]; + Zotero.Utilities.processAsync(sets, callbacks, function () { Zotero.done(); }); + Zotero.wait(); } \ No newline at end of file