Skip to content

Commit

Permalink
Fix SlideShare web translator (#1162)
Browse files Browse the repository at this point in the history
  • Loading branch information
bencomp authored and adam3smith committed Oct 22, 2016
1 parent 0c943c4 commit b281814
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions SlideShare.js
Expand Up @@ -9,37 +9,35 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2013-12-12 13:47:36"
"lastUpdated": "2016-10-17 14:24:36"
}

function scrape(doc) {
function scrape(doc, url) {
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")]');
var creator = ZU.xpathText(doc, '//div[@itemprop="author"]//span[@itemprop="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")])])');
item.abstractNote = ZU.xpathText(doc, '//p[@id="slideshow-description-paragraph"]');

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"]');
var rights = ZU.xpathText(doc, '//div[contains(@class, "license-container")]');
if (rights && rights.trim()) item.rights = rights.trim()

item.type = ZU.xpathText(doc, '//ul[@class="h-slideshow-categories"]/li[1]');
item.type = ZU.xpathText(doc, '//div[contains(@class, "categories-container")]//a[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 date = ZU.xpathText(doc, '//meta[@property = "slideshare:created_at"]/@content');
if(date) item.date = date;
item.url = url;
item.libraryCatalog = "SlideShare";

var loggedin = !doc.getElementById('login_link');
var pdfurl = ZU.xpathText(doc, '//li[@class="action-download"]/a/@href');
Expand All @@ -53,20 +51,19 @@ function scrape(doc) {

function detectWeb(doc, url) {
if (url.indexOf("/search/") != -1 &&
ZU.xpath(doc, '//ol[contains(@class, "searchResults")]\
//div[./a[@class="slideshow-title"]]').length) {
ZU.xpath(doc, '//div[contains(@class, "searchResults")]\
//div[./a[contains(@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='),
var links = ZU.xpath(doc,'//div[contains(@class, "searchResults")]\
//div[./a[contains(@class, "title-link")]]');
Zotero.selectItems( ZU.getItemArray(doc, links, 'from_search=', null),
function(items) {
if (!items) return true;

Expand All @@ -77,7 +74,7 @@ function doWeb(doc, url) {
ZU.processDocuments(shows, scrape)
});
} else {
scrape(doc);
scrape(doc, url);
}
}/** BEGIN TEST CASES **/
var testCases = [
Expand All @@ -99,8 +96,7 @@ var testCases = [
"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",
"date": "2008-03-06 10:51:58 UTC",
"url": "http://www.slideshare.net/eby/zotero-and-you-or-bibliography-on-the-semantic-web",
"presentationType": "Business"
}
Expand All @@ -112,4 +108,4 @@ var testCases = [
"items": "multiple"
}
]
/** END TEST CASES **/
/** END TEST CASES **/

0 comments on commit b281814

Please sign in to comment.