-
Notifications
You must be signed in to change notification settings - Fork 0
/
Berkeley Electronic Press.js
84 lines (77 loc) · 2.25 KB
/
Berkeley Electronic Press.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{
"translatorID":"2a5dc3ed-ee5e-4bfb-baad-36ae007e40ce",
"translatorType":4,
"label":"Berkeley Electronic Press",
"creator":"Michael Berkowitz",
"target":"http://www.bepress.com/",
"minVersion":"1.0.0b4.r5",
"maxVersion":"",
"priority":100,
"inRepository":true,
"lastUpdated":"2009-01-08 08:19:07"
}
function detectWeb(doc, url) {
if (url.match("cgi/query.cgi")) {
return "multiple";
} else if (url.match(/vol[\d+]\/iss[\d]+/)) {
return "journalArticle";
}
}
var tagMap = {
journal_title:"publicationTitle",
title:"title",
date:"date",
volume:"volume",
issue:"issue",
abstract_html_url:"url",
doi:"DOI"
}
function doWeb(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
var articles = new Array();
if (detectWeb(doc, url) == "multiple") {
var items = new Object();
var titles = doc.evaluate('//table[@id="query"]/tbody/tr/td[4]/a', doc, nsResolver, XPathResult.ANY_TYPE, null);
var next_title;
while (next_title = titles.iterateNext()) {
items[next_title.href] = next_title.textContent;
}
items = Zotero.selectItems(items);
for (var i in items) {
articles.push(i);
}
} else {
articles = [url];
}
Zotero.debug(articles);
Zotero.Utilities.processDocuments(articles, function(newDoc) {
var metatags = new Object();
var metas = newDoc.evaluate('//meta[contains(@name, "bepress_citation")]', newDoc, null, XPathResult.ANY_TYPE, null);
var next_meta;
while (next_meta = metas.iterateNext()) {
metatags[next_meta.name.replace("bepress_citation_", "")] = next_meta.content;
}
var item = new Zotero.Item("journalArticle");
//regularly mapped tags
for (var tag in tagMap) {
if (metatags[tag]) {
item[tagMap[tag]] = metatags[tag];
}
}
//authors
var authors = metatags['authors'].split(";");
for each (var author in authors) {
item.creators.push(Zotero.Utilities.cleanAuthor(author, "author"));
}
//attachments
item.attachments = [
{url:item.url, title:item.title, mimeType:"text/html"},
{url:metatags['pdf_url'], title:"Berkeley Electronic Press Full Text PDF", mimeType:"application/pdf"}
];
item.complete();
}, function() {Zotero.done();});
Zotero.wait();
}