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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
{
"translatorID": "c41c9c66-8540-4216-b138-7c00532748c9",
"label": "Gulag: Many Days, Many Lives",
"creator": "Adam Crymble",
"target": "^https?://gulaghistory\\.org",
"minVersion": "1.0.0b4.r5",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2012-01-30 22:49:27"
}
function detectWeb(doc, url) {
if (doc.evaluate('//div[@class="field"][@id="citation"]/p', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
return "book";
} else if (doc.evaluate('//h3/a', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
return "multiple";
}
}
//Gulag: Many Days, Many Lives translator; Code by Adam Crymble
function scrape(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
var newItem = new Zotero.Item("book");
if (doc.evaluate('//div[@class="field"][@id="description"]/div', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
var abstract1 = doc.evaluate('//div[@class="field"][@id="description"]/div', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
newItem.abstractNote = abstract1.replace(/^\s+|\s*$/g, '');
}
if (doc.evaluate('//div[@class="field"][@id="source"]/p', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
var rights1 = doc.evaluate('//div[@class="field"][@id="source"]/p', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
newItem.rights = rights1.replace(/^\s+|\s*$/g, '');
}
var cite = doc.evaluate('//div[@class="field"][@id="citation"]/p', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
var checkForAuthor = cite.indexOf('"');
if (cite.match("Gulag: Many Days, Many Lives")) {
var split1 = new Array();
var split2 = new Array();
var split3 = new Array();
var split4 = new Array();
var split5 = new Array();
if (checkForAuthor == 0) {
split1[1] = cite;
} else {
//author
split1 = cite.split(', "');
var authorWords = split1[0].split(/\b\s/);
if (authorWords.length > 3) {
newItem.creators.push({lastName: split1[0], creatorType: "creator"});
} else {
newItem.creators.push(Zotero.Utilities.cleanAuthor(split1[0], "author"));
}
}
//title
split2 = split1[1].split('." ');
newItem.title = split2[0];
//repository
split3 = split2[1].split("Lives, ");
//object number
split4 = split3[1].split(" (");
newItem.callNumber = split4[0];
//date posted and URL
split5 = split4[1].split(")<");
newItem.date = split5[0];
} else {
var split1 = cite.split(". ");
//Zotero.debug(split1);
//author
var author = split1[0].split(/\, /);
author = author[1] + ' ' + author[0];
//Zotero.debug(author);
newItem.creators.push(Zotero.Utilities.cleanAuthor(author, "author"));
//title
newItem.title = split1[1];
//place
var place1 = split1[2].split(":");
newItem.place = place1[0];
//date
var date1 = split1[2].split (", ");
newItem.date = date1[1];
//publisher
newItem.publisher = date1[0].replace(place1[0], '').substr(2);
}
newItem.url = doc.location.href;
newItem.complete();
}
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('//h3/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.Utilities.processDocuments(articles, scrape, function() {Zotero.done();});
Zotero.wait();
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://gulaghistory.org/items/browse?search=Siberia&submit_search=Search",
"items": "multiple"
},
{
"type": "web",
"url": "http://gulaghistory.org/items/show/47",
"items": [
{
"itemType": "book",
"creators": [
{
"firstName": "Thomas",
"lastName": "Sgovio",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [],
"abstractNote": "Map of Thomas Sgovio's two journeys. One journey took him from Moscow to Magadan, the other from Moscow beyond the Ural Mountains to Boguchani in Siberia.",
"title": "Dear America! Why I Turned Against Communism",
"place": "Kenmore, NY",
"date": "NY: Partners' Press",
"publisher": "nmore",
"url": "http://gulaghistory.org/items/show/47",
"libraryCatalog": "Gulag: Many Days, Many Lives",
"accessDate": "CURRENT_TIMESTAMP"
}
]
}
]
/** END TEST CASES **/
|