forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Digital Humanities Quarterly.js
103 lines (99 loc) · 3.05 KB
/
Digital Humanities Quarterly.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
{
"translatorID": "bbad0221-134b-495a-aa56-d77cfaa67ab5",
"label": "Digital Humanities Quarterly",
"creator": "Michael Berkowitz",
"target": "^https?://www\\.digitalhumanities\\.org/(dhq)?",
"minVersion": "1.0.0b4.r5",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsib",
"lastUpdated": "2012-01-30 22:50:51"
}
function detectWeb(doc, url) {
if (doc.evaluate('//div[@class="DHQarticle"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
return "journalArticle";
} else if (doc.evaluate('//div[@id="mainContent"]/div/p', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
return "multiple";
}
}
function scrape(doc, xpath, xdoc) {
return Zotero.Utilities.trimInternal(doc.evaluate(xpath, xdoc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
}
function doWeb(doc, url) {
var articles = new Array();
if (detectWeb(doc, url) == "multiple") {
var items = new Object;
var arts = doc.evaluate('//div[@id="mainContent"]/div/p/a', doc, null, XPathResult.ANY_TYPE, null);
var art;
while (art = arts.iterateNext()) {
items[art.href] = art.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 item = new Zotero.Item("journalArticle");
item.url = newDoc.location.href;
item.title = scrape(newDoc, '//h1[@class="articleTitle"]', newDoc);
var voliss = scrape(newDoc, '//div[@id="pubInfo"]', newDoc);
voliss = voliss.match(/(.*)Volume\s+(\d+)\s+Number\s+(\d+)/);
item.date = voliss[1];
item.volume = voliss[2];
item.issue = voliss[3];
var authors = newDoc.evaluate('//div[@class="author"]', newDoc, null, XPathResult.ANY_TYPE, null);
var aut;
while (aut = authors.iterateNext()) {
item.creators.push(Zotero.Utilities.cleanAuthor(scrape(newDoc, './a[1]', aut), "author"));
}
item.attachments = [{url:item.url, title:"DHQ Snapshot", mimeType:"text/html"}];
item.complete();
}, function() {Zotero.done();});
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://www.digitalhumanities.org/dhq/vol/5/2/000094/000094.html",
"items": [
{
"itemType": "journalArticle",
"creators": [
{
"firstName": "Wesley",
"lastName": "Beal",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"url": "http://www.digitalhumanities.org/dhq/vol/5/2/000094/000094.html",
"title": "DHQ Snapshot",
"mimeType": "text/html"
}
],
"url": "http://www.digitalhumanities.org/dhq/vol/5/2/000094/000094.html",
"title": "Network Narration in John Dos Passos’s U.S.A. Trilogy",
"date": "Spring 2011",
"volume": "5",
"issue": "2",
"libraryCatalog": "Digital Humanities Quarterly",
"accessDate": "CURRENT_TIMESTAMP"
}
]
},
{
"type": "web",
"url": "http://www.digitalhumanities.org/dhq/vol/5/1/index.html",
"items": "multiple"
}
]
/** END TEST CASES **/