summaryrefslogtreecommitdiff
path: root/Hispanic-American Periodical Index (Beta).js
blob: 2193f648ab4d4717cdf9552d98fe72d91f4dc381 (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
{
	"translatorID": "cc4b1ea4-3349-4bb4-af55-cce5e06e4669",
	"label": "Hispanic-American Periodical Index (Beta)",
	"creator": "Sebastian Karcher",
	"target": "^https?://hapi\\.ucla\\.edu",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsb",
	"lastUpdated": "2014-09-07 10:21:42"
}

/*
	***** BEGIN LICENSE BLOCK *****
	
	Copyright © 2014 Sebastian Karcher
	This file is part of Zotero.
	
	Zotero is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	Zotero 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 Affero General Public License for more details.
	
	You should have received a copy of the GNU Affero General Public License
	along with Zotero.  If not, see <http://www.gnu.org/licenses/>.
	
	***** END LICENSE BLOCK *****
*/

function detectWeb(doc, url) {
    if (url.indexOf("article/citation") != -1) return "journalArticle";
    else if (url.indexOf("/search") != -1 || url.indexOf("/name/") != -1) return "multiple";
}

function scrape(doc, url) {
    var id = url.match(/citation\/(\d+)/)[1];
    var token = ZU.xpathText(doc, '(//input[@name="csrf_token"])[1]/@value');
    //Z.debug(id);
    //Z.debug(token);
    var post = "csrf_token=" + token + "&articles=" + id;
    var get = "/article/export_for_endnote/";
    Zotero.Utilities.HTTP.doPost(get, post, function(text) {
        //Z.debug(text);
        var translator = Zotero.loadTranslator("import");
        // Calling the RIS translator
        translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
        translator.setString(text);
        translator.setHandler("itemDone", function(obj, item) {
            item.notes = [];
            item.attachments = [{
                document: doc,
                title: "HAPI Snapshot"
            }];
            item.complete();
        });
        translator.translate();
    });

}

function doWeb(doc, url) {
    var articles = new Array();
    var items = {};
    if (detectWeb(doc, url) == "multiple") {
        var titles = ZU.xpath(doc, '//span[@class="title-link"]');
        for (var i = 0; i < titles.length; i++) {
            items[ZU.xpathText(titles[i], './@data-title')] = titles[i].textContent;
        }
        Zotero.selectItems(items, function(items) {
            if (!items) {
                return true;
            }
            for (var i in items) {
                articles.push("article/citation/" + i);
            }
            Zotero.Utilities.processDocuments(articles, scrape);
        });
    } else {
        scrape(doc, url);
    }
}
/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://newstaging.hapi.imagistic.com/article/citation/308849",
		"items": [
			{
				"itemType": "journalArticle",
				"creators": [
					{
						"lastName": "Seveso",
						"firstName": "César",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"Peronism",
					"Social conflict--Argentina",
					"Labor and laboring classes--Argentina--Political activity",
					"culture",
					"gender",
					"memory",
					"violence"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "HAPI Snapshot"
					}
				],
				"title": "Millions of Small Battles: The Peronist Resistance in Argentina",
				"publicationTitle": "Bulletin of Latin American Research",
				"volume": "30",
				"issue": "3",
				"pages": "313–327",
				"url": "http://onlinelibrary.wiley.com/journal/10.1111/%28ISSN%291470-9856/issues",
				"date": "2011",
				"libraryCatalog": "Hispanic-American Periodical Index (Beta)",
				"accessDate": "CURRENT_TIMESTAMP",
				"shortTitle": "Millions of Small Battles"
			}
		]
	}
]
/** END TEST CASES **/