summaryrefslogtreecommitdiff
path: root/IGN.js
blob: 14acbd79a8eafbd5f37e16d19bcbeb9594a554b2 (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
{
	"translatorID": "d210c5a1-73e1-41ad-a3c9-331d5a3ead48",
	"label": "IGN",
	"creator": "odie5533",
	"target": "^https?://[^/]*\\.ign\\.com/",
	"minVersion": "1.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsibv",
	"lastUpdated": "2014-04-03 17:39:52"
}

/*
	IGN Translator - Parses IGN articles and creates Zotero-based metadata
	Copyright (C) 2010-2011 odie5533

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

function detectWeb(doc, url) {
	if (url.match(/articles/)) {
		return "webpage";
	}
}

function scrape(doc, url) {
	var newItem = new Zotero.Item("webpage");
	newItem.publicationTitle = "IGN";
	newItem.url = doc.location.href;
	newItem.title = doc.title.replace(/ -[^-]+IGN/, "");
	
	// pages
	var pages = doc.evaluate('//div[@class="ui-page-list clear"]/ul/li[last()-1]', doc, null, XPathResult.ANY_TYPE, null);
	if (p = pages.iterateNext())
		newItem.pages = p.textContent;
	
	// date
	var dates = doc.evaluate('//div[@class="article_pub_date"]/text()', doc, null, XPathResult.ANY_TYPE, null);
	newItem.date = dates.iterateNext().textContent.replace(/^\s+|\s+$/g,'');
	
	//authors
	var byline = doc.evaluate('//div[@class="article_author"]', doc, null, XPathResult.ANY_TYPE, null);
	var authors = byline.iterateNext().textContent.replace(/^by\s*/, "").split(" and ");
	for each(var a in authors) {
		newItem.creators.push(Zotero.Utilities.cleanAuthor(a, "author"));
	}
	
	// attach html
	newItem.attachments.push({title:"IGN Article Snapshot", document:doc});
	
	newItem.complete();
}

function doWeb(doc, url) {
	scrape(doc, url);
}
/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://www.ign.com/articles/2011/11/04/5-reasons-modern-warfare-3-wont-disappoint",
		"items": [
			{
				"itemType": "webpage",
				"creators": [
					{
						"firstName": "Stephen",
						"lastName": "Lambrechts",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [
					{
						"title": "IGN Article Snapshot"
					}
				],
				"publicationTitle": "IGN",
				"url": "http://www.ign.com/articles/2011/11/04/5-reasons-modern-warfare-3-wont-disappoint",
				"title": "5 Reasons Modern Warfare 3 Won't Disappoint",
				"date": "November 3, 2011",
				"libraryCatalog": "IGN",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	}
]
/** END TEST CASES **/