summaryrefslogtreecommitdiff
path: root/Inter-Research Science Center.js
blob: b58f3c4f491419b3b1d7f377330d79564cc47ac5 (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
{
	"translatorID": "0eeb2ac0-fbaf-4994-b98f-203d273eb9fa",
	"label": "Inter-Research Science Center",
	"creator": "Michael Berkowitz",
	"target": "^https?://www\\.int-res\\.com/",
	"minVersion": "1.0.0b4.r5",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsibv",
	"lastUpdated": "2013-04-14 21:10:24"
}

function detectWeb(doc, url) {
	if (doc.evaluate('//div[@class="journal-index"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext() ||
		doc.evaluate('//div[@class="tx-indexedsearch-res"]//tr[1]/td[2]//a', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
		return "multiple";
	} else if (doc.evaluate('//a[@class="citeexport"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
		return "journalArticle";
	}
}

var journals = {
	meps:["Marine Ecology Progress Series", "Mar Ecol Prog Ser"],
	ab:["Aquatic Biology", "Aquat Biol"],
	ame:["Aquatic Microbial Ecology", "Aquat Microb Ecol"],
	dao:["Diseases of Aquatic Organisms", "Dis Aquat Org"],
	cr:["Climate Research", "Clim Res"],
	esr:["Endangered Species Research", "Endang Species Res"]
};

function doWeb(doc, url) {
	var arts = new Array();
	if (detectWeb(doc, url) == "multiple") {
		var items = new Object();
		if (doc.evaluate('//div[@class="tx-indexedsearch-res"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
			var titlesx = doc.evaluate('//div[@class="tx-indexedsearch-res"]//tr[2]/td[2]', doc, null, XPathResult.ANY_TYPE, null);
			var linksx = doc.evaluate('//div[@class="tx-indexedsearch-res"]//tr[1]/td[2]//a', doc, null, XPathResult.ANY_TYPE, null);
			var title;
			var link;
			while ((title = titlesx.iterateNext()) && (link = linksx.iterateNext())) {
				items[link.href] = Zotero.Utilities.trimInternal(title.textContent).match(/doi:\s+[^\s]+\s+(.*)$/)[1];
			}
		} else {
			var stuff = doc.evaluate('//div[@class="journal-index"]/*[a[contains(text(), "pdf format")]]', doc, null, XPathResult.ANY_TYPE, null);
			var thing;
			var titles = "";
			while (thing = stuff.iterateNext()) {
				titles += thing.textContent;
			}
			titles = titles.split(/\n/);
			//Zotero.debug(titles);
			var names = new Array();
			for (var i = 0; i < titles.length; i++) {
				if (((i-1)%2 == 0) && (titles[i].match(/\w+/))) {
					names.push(titles[i]);
				}
			}
			//Zotero.debug(names);
			var links = doc.evaluate('//div[@class="journal-index"]/*[a[contains(text(), "pdf format")]]/a[1]', doc, null, XPathResult.ANY_TYPE, null);
			var link;
			while (link = links.iterateNext()) {
				items[link.href] = names.shift();
			}
		}
		Zotero.selectItems(items, function (items) {
			if (!items) {
				return true;
			}
			for (var i in items) {
				arts.push(i);
			}
			Zotero.Utilities.processDocuments(arts, scrape);	
		});
	} else {
		scrape(doc, url)
	}
}	
	
function scrape(doc, url){
		var item = new Zotero.Item("journalArticle");
		item.title = Zotero.Utilities.trimInternal(doc.evaluate('//div[@class="bb"]/h2', doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
		item.url = doc.location.href;
		var voliss = item.url.match(/v(\d+)\/(n(\d+)\/)?p([^/]+)\//);
		item.volume = voliss[1];
		item.pages = voliss[4];
		if (voliss[2]) item.issue = voliss[3];
		var jour = item.url.match(/abstracts\/([^/]+)\//)[1];
		item.publicationTitle = journals[jour][0];
		item.journalAbbreviation = journals[jour][1];
		item.abstractNote = Zotero.Utilities.trimInternal(doc.evaluate('//p[@class="abstract_block"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
		var authors = Zotero.Utilities.trimInternal(doc.evaluate('//div[@class="bb"]/h3', doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent).split(/,\s+/);
		for each (var aut in authors) {
			aut = aut.replace(/[^\w^\s^\.]/g, "").replace(/\d/g, "");
			item.creators.push(Zotero.Utilities.cleanAuthor(aut, "author"));
		}
		item.date = doc.evaluate('//div[@class="abs-footer"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent.match(/date:\s+(.*)/)[1];
		item.DOI = Zotero.Utilities.trimInternal(doc.evaluate('//h1[@class="csc-secondHeader"]/span', doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent).match(/doi:\s*(.*)/)[1];
		var tags = doc.evaluate('//div[@class="box"]/p/a', doc, null, XPathResult.ANY_TYPE, null);
		var tag;
		while (tag = tags.iterateNext()) {
			item.tags.push(tag.textContent);
		}		
		var pdfurl = doc.evaluate('//a[contains(@href, ".pdf")]', doc, null, XPathResult.ANY_TYPE, null).iterateNext().href;
		item.attachments = [
			{url:item.url, title:item.publicationTitle + " Snapshot", mimeType:"text/html"},
			{url:pdfurl, title:item.publicationTitle + " Full Text PDF", mimeType:"application/pdf"}
		];
		item.complete();
}/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://www.int-res.com/abstracts/meps/v403/",
		"items": "multiple"
	},
	{
		"type": "web",
		"url": "http://www.int-res.com/abstracts/meps/v403/p13-27/",
		"items": [
			{
				"itemType": "journalArticle",
				"creators": [
					{
						"firstName": "Kyle C.",
						"lastName": "Cavanaugh",
						"creatorType": "author"
					},
					{
						"firstName": "David A.",
						"lastName": "Siegel",
						"creatorType": "author"
					},
					{
						"firstName": "Brian P.",
						"lastName": "Kinlan",
						"creatorType": "author"
					},
					{
						"firstName": "Daniel C.",
						"lastName": "Reed",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [
					{
						"url": "http://www.int-res.com/abstracts/meps/v403/p13-27/",
						"title": "Marine Ecology Progress Series Snapshot",
						"mimeType": "text/html"
					},
					{
						"url": "http://www.int-res.com/articles/meps_oa/m403p013.pdf",
						"title": "Marine Ecology Progress Series Full Text PDF",
						"mimeType": "application/pdf"
					}
				],
				"title": "Scaling giant kelp field measurements to regional scales using satellite observations",
				"url": "http://www.int-res.com/abstracts/meps/v403/p13-27/",
				"volume": "403",
				"pages": "13-27",
				"publicationTitle": "Marine Ecology Progress Series",
				"journalAbbreviation": "Mar Ecol Prog Ser",
				"abstractNote": "ABSTRACT: Little is known about the local to regional scale variability in biomass and productivity of many subtidal ecosystems, as appropriate field surveys are both time and labor intensive. Here, we combined high-resolution satellite imagery with aerial photos and diver sampling to assess changes in giant kelp Macrocystis pyrifera canopy cover and biomass along a ~60 km stretch of coastline in the Santa Barbara Channel, California, USA. Our objectives were to (1) develop new methods for estimating giant kelp canopy cover and biomass using satellite imagery, and (2) assess temporal changes in kelp forest biomass across multiple spatial scales. Results of the satellite kelp cover classification compared very favorably with near-coincident high-resolution aerial camera surveys (r2 = 0.90). Monthly diver observations of biomass for fixed plots at 3 kelp forest sites were strongly correlated with satellite determinations of normalized difference vegetation index (NDVI) signals (r2 = 0.77). This allowed us to examine variation in giant kelp biomass across multiple spatial scales (pixel, plot, site, and region). The relationship between plot scale (40 m) changes in biomass and remote assessments of site scale (~1 km) changes varied among sites and depended on the relative location of the plot and the size of the kelp forest at each site. Changes in biomass among sites were well correlated with each other and with the aggregated regional (~60 km) total. Linking field measurements of giant kelp biomass made on a plot scale with regional estimates made by satellite facilitates an understanding of the regional patterns and drivers of biomass and primary production of giant kelp forest ecosystems.",
				"date": "March 22, 2010",
				"DOI": "10.3354/meps08467",
				"libraryCatalog": "Inter-Research Science Center",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	}
]
/** END TEST CASES **/