This repository has been archived by the owner on Jan 3, 2020. It is now read-only.
forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlideShare.js
115 lines (103 loc) · 4 KB
/
SlideShare.js
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
{
"translatorID": "0cc8e259-106e-4793-8c26-6ec8114a9160",
"label": "SlideShare",
"creator": "Michael Berkowitz",
"target": "https?://[^/]*slideshare\\.net/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2013-12-12 13:47:36"
}
function scrape(doc) {
var item = new Zotero.Item("presentation");
item.title = ZU.xpathText(doc, '(//meta[@name="title" or @property="og:title"]/@content)[1]') ||
ZU.xpathText(doc, '/html/head/title');
var creator = ZU.xpathText(doc, '//meta[@name="dc_creator"]/@content') ||
ZU.xpathText(doc, '//a[contains(@class,"h-author-name")]');
if(creator && creator.trim())
item.creators.push({lastName:creator.trim(), creatorType:'author'});
item.abstractNote = ZU.xpathText(doc, '(//p[contains(@class, "descriptionExpanded")] |\
//p[contains(@class, "description") and\
not(following-sibling::p[contains(@class, "descriptionExpanded")])])');
var tags = ZU.xpathText(doc, '//meta[contains(@name, "slideshow_tag")]/@content');
if (tags) tags = tags.split(/\s*,\s*/);
for(var i in tags) {
item.tags.push(tags[i].trim());
}
item.rights = ZU.xpathText(doc, '//p[@class="license"]');
item.type = ZU.xpathText(doc, '//ul[@class="h-slideshow-categories"]/li[1]');
var date = ZU.xpathText(doc, '//meta[contains(@property, "updated_at")]/@content');
if(date) item.date = date.replace(/\d{2}:\d{2}:\d{2}\s+[+-]\d{4}/, "")
item.url = doc.location.href
item.repository = "SlideShare";
var loggedin = !doc.getElementById('login_link');
var pdfurl = ZU.xpathText(doc, '//li[@class="action-download"]/a/@href');
if(loggedin && pdfurl) {
//is this always pdf?
item.attachments.push({url:pdfurl, title:"SlideShare Slide Show", mimeType:"application/pdf"});
}
item.complete();
}
function detectWeb(doc, url) {
if (url.indexOf("/search/") != -1 &&
ZU.xpath(doc, '//ol[contains(@class, "searchResults")]\
//div[./a[@class="slideshow-title"]]').length) {
return "multiple";
} else if ((ZU.xpathText(doc, '//meta[@name="og_type"]/@content') && ZU.xpathText(doc, '//meta[@name="og_type"]/@content') == 'article') || (ZU.xpathText(doc, '//meta[@name="og_type"]/@content') && ZU.xpathText(doc, '//meta[@name="og_type"]/@content').search(/presentation/)!=-1)) {
return "presentation";
}
}
function doWeb(doc, url) {
var shows = new Array();
if (detectWeb(doc, url) == "multiple") {
var links = ZU.xpath(doc,'//ol[contains(@class, "searchResults")]\
//div[./a[@class="slideshow-title"]]');
Zotero.selectItems( ZU.getItemArray(doc, links, null,'from_search='),
function(items) {
if (!items) return true;
var shows = new Array();
for (var i in items) {
shows.push(i);
}
ZU.processDocuments(shows, scrape)
});
} else {
scrape(doc);
}
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://www.slideshare.net/eby/zotero-and-you-or-bibliography-on-the-semantic-web",
"items": [
{
"itemType": "presentation",
"creators": [
{
"lastName": "eby",
"creatorType": "author"
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [],
"title": "Zotero and You, or Bibliography on the Semantic Web",
"abstractNote": "Representatives from the Center for History and New Media will introduce Zotero, a free and open source extension for Firefox that allows you to collect, organize and archive your research materials. After a brief demo and explanation, we will discuss best practices for making your projects \"Zotero ready\" and other opportunities to integrate with your digital projects through the Zotero API.",
"rights": "© All Rights Reserved",
"date": "2008-03-06 16:51:58 UTC",
"url": "http://www.slideshare.net/eby/zotero-and-you-or-bibliography-on-the-semantic-web",
"presentationType": "Business"
}
]
},
{
"type": "web",
"url": "http://www.slideshare.net/search/slideshow?searchfrom=header&q=zotero",
"items": "multiple"
}
]
/** END TEST CASES **/