summaryrefslogtreecommitdiff
path: root/MetaPress.js
blob: 0b741febbe8917f2b72bafda999aee0d5f4fbffc (plain)
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
{
	"translatorID": "62c0e36a-ee2f-4aa0-b111-5e2cbd7bb5ba",
	"label": "MetaPress",
	"creator": "Michael Berkowitz, Sebastian Karcher",
	"target": "https?://(.*)metapress\\.com/",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsibv",
	"lastUpdated": "2014-08-05 03:26:18"
}

function detectWeb(doc, url) {
	if (ZU.xpath(doc, '//div[@class="primitive article"]/h2/a[1]').length > 0) {
		return "multiple";
	} else if (url.match(/content\/[^?/]/)) {
		var headingLabel = doc.getElementById('ctl00_PageHeadingLabel');
		if(!headingLabel) {
			Z.debug('Heading not found. Defaulting to journalArticle');
			return 'journalArticle';
		};
		
		var type = ZU.trimInternal(headingLabel.textContent).toLowerCase()
		switch(type) {
			case 'book chapter':
				return 'bookSection';
			case 'journal article':
				return 'journalArticle';
			default:
				Z.debug('Unrecognized heading: ' + type);
				return "journalArticle";
		}
	}
}

function doWeb(doc, url) {
	if (detectWeb(doc, url) == "multiple") {
		var hits = {};
		var urls = [];
		var results = ZU.xpath(doc, '//div[@class="primitive article"]/h2/a[1]');
		for (var i in results) {
			hits[results[i].href] = results[i].textContent;
		}
		Z.selectItems(hits, function (items) {
			if (items == null) return true;
			for (var j in items) {
				urls.push(j);
			}
			ZU.processDocuments(urls, scrape);
		})
	} else {
		scrape(doc, url)
	}
}

function scrape(doc, url) {
	var host = doc.location.host;
	var artid = url.match(/content\/([^\/]+)/)[1];
	
	ZU.doPost('/export.mpx', 'code=' + artid + '&mode=ris', function (text) {
		//some entries have empty author fields, or fields with just a comma. Delete those.
		text = text.replace(/AU  - [\s,]+\n/g, "");
		//book chapters are supposed to be CHAP not CHAPTER
		text = text.replace(/TY\s+-\s+CHAP.+/g, 'TY  - CHAP');
		
		// load translator for RIS
		var translator = Zotero.loadTranslator("import");
		translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
		translator.setString(text);
		translator.setHandler("itemDone", function (obj, item) {
			// See http://trb.metapress.com/content/y86nu17g47k25610/?p=f7c9780b9aea4ad982d8ccb3d10010d8&pi=0
			if(item.issue == '-1') delete item.issue;
			
			var pdfurl = 'http://' + host +'/content/' + artid + '/fulltext.pdf';
			item.attachments = [{
				url: item.url,
				title: "MetaPress Snapshot",
				mimeType: "text/html"
			}, {
				url: pdfurl,
				title: "MetaPress Full Text PDF",
				mimeType: "application/pdf"
			}];
			
			if (item.abstractNote && item.abstractNote.substr(0, 8) == "Abstract") {
				item.abstractNote = ZU.trimInternal(item.abstractNote.substr(8));
			}
			
			item.complete();
		});
		translator.translate();
	});
}/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://metapress.com/content/y737165n6x0q1455/",
		"items": [
			{
				"itemType": "journalArticle",
				"title": "Immigration and Unemployment of Skilled and Unskilled Labor",
				"creators": [
					{
						"lastName": "Yabuuchi",
						"firstName": "Shigemi",
						"creatorType": "author"
					}
				],
				"date": "June 1, 2008",
				"abstractNote": "This paper discusses the problem of unemployment in developed countries that faces international labor movement. There are two types of unemployment. The first traditional type of unemployment exists simply because the common wage rate is fixed and higher than the equilibrium level. The second one may exist when the wage rate in one sector is high and fixed, while that in the other is flexible. On the other hand, an extensive movement of labor among countries has been observed. Thus, this paper investigates the effects of immigration and other policies on the two types of unemployment. JEL classification : F16, F22, J64, R23",
				"accessDate": "CURRENT_TIMESTAMP",
				"issue": "2",
				"libraryCatalog": "MetaPress",
				"pages": "331-345",
				"publicationTitle": "Journal of Economic Integration",
				"url": "http://www.metapress.com/content/Y737165N6X0Q1455",
				"volume": "23",
				"attachments": [
					{
						"title": "MetaPress Snapshot",
						"mimeType": "text/html"
					},
					{
						"title": "MetaPress Full Text PDF",
						"mimeType": "application/pdf"
					}
				],
				"tags": [],
				"notes": [],
				"seeAlso": []
			}
		]
	},
	{
		"type": "web",
		"url": "http://metapress.com/content/?k=labor+market",
		"items": "multiple"
	},
	{
		"type": "web",
		"url": "http://metapress.com/content/j99677822343/?v=editorial",
		"items": "multiple"
	},
	{
		"type": "web",
		"url": "http://brepols.metapress.com/content/V4G02936X2860845",
		"items": [
			{
				"itemType": "bookSection",
				"title": "The Regular Canons in the Medieval British Isles",
				"creators": [
					{
						"lastName": "Abram",
						"firstName": "Andrew",
						"creatorType": "author"
					}
				],
				"date": "2011",
				"DOI": "10.1484/M.MCS-EB.5.100378",
				"accessDate": "CURRENT_TIMESTAMP",
				"libraryCatalog": "MetaPress",
				"pages": "79-95",
				"publicationTitle": "Medieval Church Studies",
				"url": "http://dx.doi.org/10.1484/M.MCS-EB.5.100378",
				"attachments": [
					{
						"title": "MetaPress Snapshot",
						"mimeType": "text/html"
					},
					{
						"title": "MetaPress Full Text PDF",
						"mimeType": "application/pdf"
					}
				],
				"tags": [],
				"notes": [],
				"seeAlso": []
			}
		]
	},
	{
		"type": "web",
		"url": "http://trb.metapress.com/content/y86nu17g47k25610/?p=f7c9780b9aea4ad982d8ccb3d10010d8&pi=0",
		"items": [
			{
				"itemType": "journalArticle",
				"title": "1997-1998 Survey of Potential North American Applications for Emerging Diesel Multiple Unit Technologies",
				"creators": [
					{
						"lastName": "Pieri",
						"firstName": "Gerald",
						"creatorType": "author"
					},
					{
						"lastName": "Nelson",
						"firstName": "David",
						"creatorType": "author"
					}
				],
				"date": "January 1, 1999",
				"DOI": "10.3141/1677-06",
				"abstractNote": "The results of a survey done in the United States and Canada in 1997 and 1998 are presented. The survey was done to determine the level of interest among current and potential commuter rail operations in applying emerging technologies for self-propelled, diesel multiple unit (DMU) rail passenger cars. Interest in DMU rail passenger cars is waxing across the continent as commuter rail grows in popularity as a transit mode and operators search for possible alternatives to push-pull diesel equipment. The survey team contacted representatives of 58 operators, regional transit agencies, planning agencies, state departments of transportation, and other agencies. Twenty-eight of the respondents currently operate or oversee commuter or regional rail service and 30 do not. The principal survey was conducted in 1997 with follow-on surveys of selected jurisdictions in 1998. Of the 58 potential operators, 19 do not foresee DMU use, 8 currently operate DMUs, 2 are actively implementing DMU plans, and the remaining 29 are considering DMUs for future applications in their jurisdictions. At least 14 potential operators have hosted DMU demonstrations. Two sections are presented: ( a ) a summary of findings and observations with a summary table of survey results, and ( b ) details on each jurisdiction surveyed covering current operations, plans, and orientation toward DMU applications.",
				"libraryCatalog": "MetaPress",
				"pages": "48-57",
				"publicationTitle": "Transportation Research Record: Journal of the Transportation Research Board",
				"url": "http://dx.doi.org/10.3141/1677-06",
				"volume": "1677",
				"attachments": [
					{
						"title": "MetaPress Snapshot",
						"mimeType": "text/html"
					},
					{
						"title": "MetaPress Full Text PDF",
						"mimeType": "application/pdf"
					}
				],
				"tags": [],
				"notes": [],
				"seeAlso": []
			}
		]
	}
]
/** END TEST CASES **/