summaryrefslogtreecommitdiff
path: root/Electronic Colloquium on Computational Complexity.js
blob: 80bc4a5d31e24fee2c4f314014c70516aeb446fa (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
{
	"translatorID": "09a9599e-c20e-a405-d10d-35ad4130a426",
	"label": "Electronic Colloquium on Computational Complexity",
	"creator": "Jonas Schrieb",
	"target": "^https?://(www\\.)?eccc\\.(uni-trier|hpi-web)\\.de/",
	"minVersion": "1.0.0b3.r1",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsib",
	"lastUpdated": "2014-04-03 17:35:30"
}

function detectWeb(doc, url) {
	var singleRe   = /^https?:\/\/(www\.)?eccc\.(uni-trier|hpi-web)\.de\/report\/\d{4}\/\d{3}/;
	var multipleRe = /^https?:\/\/(www\.)?eccc\.(uni-trier|hpi-web)\.de\/(title|year|keyword)\//;
	if(singleRe.test(url)) {
		return "report";
	} else if(multipleRe.test(url)) {
		return "multiple";
	}
}

function scrape(doc) {
	var newItem = new Zotero.Item("report");

	var url = doc.location.href;
	var tmp  = url.match(/\/(\d{4})\/(\d{3})\/$/);
	newItem.date = tmp[1];
	newItem.reportNumber = tmp[2];
	newItem.url = url;
	


	var titleXPath    = "id('box')//h4";
	newItem.title = doc.evaluate(titleXPath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;



	var authorsXPath  = "id('box')//a[contains(@href,'author')]";
	var authors = doc.evaluate(authorsXPath, doc, null, XPathResult.ANY_TYPE, null);
	var nextAuthor;
	while (nextAuthor = authors.iterateNext()) {
		newItem.creators.push(Zotero.Utilities.cleanAuthor(nextAuthor.textContent, "author"));
	}


	
	var keywordsXPath = "id('box')//a[contains(@href,'keyword')]";
	var keywords = doc.evaluate(keywordsXPath, doc, null, XPathResult.ANY_TYPE, null);
	var nextKeyword;
	var i = 0;
	while (nextKeyword = keywords.iterateNext()) {
		newItem.tags[i++] = nextKeyword.textContent;
	}



	var abstractXPath = "id('box')/text()";
	var abstractLines = doc.evaluate(abstractXPath, doc, null, XPathResult.ANY_TYPE, null);
	newItem.abstractNote = "";
	var nextLine;
	while(nextLine = abstractLines.iterateNext()) {
		newItem.abstractNote += nextLine.textContent;
	}



	newItem.attachments = [
		{url:url, title:"ECCC Snapshot", mimeType:"text/html"},
		{url:url+"download", title:"ECCC Full Text PDF", mimeType:"application/pdf"}
	];

	newItem.complete();
}

function doWeb(doc, url) {
	var articles = new Array();
	var items = new Object();
	var nextTitle;

	if (detectWeb(doc, url) == "multiple") {
		var titleXPath = "//a[starts-with(@href,'/report/')]/h4";
		var linkXPath = "//a[starts-with(@href,'/report/')][h4]";

		var titles = doc.evaluate(titleXPath, doc, null, XPathResult.ANY_TYPE, null);
		var links  = doc.evaluate(linkXPath,  doc, null, XPathResult.ANY_TYPE, null);
		while (nextTitle = titles.iterateNext()) {
			nextLink = links.iterateNext();
			items[nextLink.href] = nextTitle.textContent;
		}
		Zotero.selectItems(items, function (items) {
			if (!items) {
				Zotero.done();
			}
			for (var i in items) {
				articles.push(i);
			}
			ZU.processDocuments(articles, scrape);
		});
	} else {
		scrape(doc, url)
	}
}
/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://eccc.hpi-web.de/report/2006/067/",
		"items": [
			{
				"itemType": "report",
				"creators": [
					{
						"firstName": "Heiner",
						"lastName": "Ackermann",
						"creatorType": "author"
					},
					{
						"firstName": "Heiko",
						"lastName": "Röglin",
						"creatorType": "author"
					},
					{
						"firstName": "Berthold",
						"lastName": "Vöcking",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"Combinatorial Structure",
					"Congestion Games",
					"Convergence Time",
					"PLS-Completeness"
				],
				"seeAlso": [],
				"attachments": [
					{
						"url": "http://eccc.hpi-web.de/report/2006/067/",
						"title": "ECCC Snapshot",
						"mimeType": "text/html"
					},
					{
						"url": "http://eccc.hpi-web.de/report/2006/067/download",
						"title": "ECCC Full Text PDF",
						"mimeType": "application/pdf"
					}
				],
				"date": "2006",
				"reportNumber": "067",
				"url": "http://eccc.hpi-web.de/report/2006/067/",
				"title": "On the Impact of Combinatorial Structure on Congestion Games",
				"abstractNote": "",
				"libraryCatalog": "Electronic Colloquium on Computational Complexity",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	},
	{
		"type": "web",
		"url": "http://eccc.hpi-web.de/keyword/13486/",
		"items": "multiple"
	}
]
/** END TEST CASES **/