Skip to content

Commit

Permalink
Springer Link: Various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
AbeJellinek committed Apr 11, 2022
1 parent 0dadeb7 commit 3c1b1f2
Showing 1 changed file with 51 additions and 18 deletions.
69 changes: 51 additions & 18 deletions Springer Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsbv",
"lastUpdated": "2020-09-08 02:04:42"
"browserSupport": "gcsibv",
"lastUpdated": "2022-04-11 21:24:58"
}

/*
Expand All @@ -31,13 +31,13 @@
*/

function detectWeb(doc, url) {
var action = url.match(/^https?:\/\/[^/]+\/([^/?#]+)/);
var action = getAction(url);
if (!action) return false;
if (!doc.head || !doc.head.getElementsByTagName('meta').length) {
Z.debug("Springer Link: No head or meta tags");
return false;
}
switch (action[1]) {
switch (action) {
case "search":
case "journal":
case "book":
Expand All @@ -61,6 +61,10 @@ function detectWeb(doc, url) {
return false;
}

function getAction(url) {
return (url.match(/^https?:\/\/[^/]+\/([^/?#]+)/) || [])[1];
}

function getResultList(doc) {
var results = ZU.xpath(doc,
'//ol[@class="content-item-list"]/li/*[self::h3 or self::h2]/a');
Expand All @@ -87,6 +91,9 @@ function doWeb(doc, url) {
if (type == "multiple") {
var list = getResultList(doc);
var items = {};
if (getAction(url) == 'book') {
items[url] = '[Full Book] ' + text(doc, 'main h1');
}
for (var i = 0, n = list.length; i < n; i++) {
items[list[i].href] = list[i].textContent;
}
Expand Down Expand Up @@ -178,7 +185,8 @@ function complementItem(doc, item) {
// series/seriesNumber
if (!item.series) {
item.series = ZU.xpathText(doc, '//dd[@id="abstract-about-book-series-title"]')
|| ZU.xpathText(doc, '//div[contains(@class, "ArticleHeader")]//a[contains(@href, "/bookseries/")]');
|| ZU.xpathText(doc, '//div[contains(@class, "ArticleHeader")]//a[contains(@href, "/bookseries/")]')
|| text(doc, '.c-chapter-book-series > a');
}
if (!item.seriesNumber) {
item.seriesNumber = ZU.xpathText(doc, '//dd[@id="abstract-about-book-series-volume"]');
Expand All @@ -204,15 +212,40 @@ function complementItem(doc, item) {
if (tags && (!item.tags || item.tags.length === 0)) {
item.tags = tags.split(',');
}
tags = doc.querySelectorAll('.c-article-subject-list__subject');
if (tags.length && !item.tags.length) {
item.tags = [...tags].map(el => el.innerText);
}
return item;
}

function scrape(doc, url) {
var DOI = url.match(/\/(10\.[^#?]+)/)[1];
var risURL = "https://citation-needed.springer.com/v2/references/" + DOI + "?format=refman&flavour=citation";
// Z.debug("risURL" + risURL);
var pdfURL = "/content/pdf/" + encodeURIComponent(DOI) + ".pdf";
// Z.debug("pdfURL: " + pdfURL);

if (getAction(url) == 'book') {
let search = Zotero.loadTranslator('search');
search.setSearch({ DOI });
search.setHandler('translators', (obj, translators) => {
search.setTranslator(translators);
search.setHandler('itemDone', (obj, item) => {
item = complementItem(doc, item);
item.attachments.push({
url: pdfURL,
title: "Full Text PDF",
mimeType: "application/pdf"
});
item.complete();
});
search.translate();
});
search.getTranslators();
return;
}

var risURL = "https://citation-needed.springer.com/v2/references/" + DOI + "?format=refman&flavour=citation";
// Z.debug("risURL" + risURL);
ZU.doGet(risURL, function (text) {
// Z.debug(text)
var translator = Zotero.loadTranslator("import");
Expand All @@ -223,7 +256,7 @@ function scrape(doc, url) {

item.attachments.push({
url: pdfURL,
title: "Springer Full Text PDF",
title: "Full Text PDF",
mimeType: "application/pdf"
});
item.complete();
Expand Down Expand Up @@ -277,7 +310,7 @@ var testCases = [
"series": "Lecture Notes in Computer Science",
"attachments": [
{
"title": "Springer Full Text PDF",
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
Expand Down Expand Up @@ -318,7 +351,7 @@ var testCases = [
"url": "https://doi.org/10.1007/978-0-387-79061-9_5173",
"attachments": [
{
"title": "Springer Full Text PDF",
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
Expand Down Expand Up @@ -362,7 +395,7 @@ var testCases = [
"url": "https://doi.org/10.1007/978-1-60761-839-3_22",
"attachments": [
{
"title": "Springer Full Text PDF",
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
Expand Down Expand Up @@ -485,7 +518,7 @@ var testCases = [
"volume": "17",
"attachments": [
{
"title": "Springer Full Text PDF",
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
Expand Down Expand Up @@ -543,25 +576,25 @@ var testCases = [
"url": "https://doi.org/10.1007/0-387-24250-3_4",
"attachments": [
{
"title": "Springer Full Text PDF",
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
"tags": [
{
"tag": " peer interaction "
"tag": "Social mediation"
},
{
"tag": " revision "
"tag": "peer interaction"
},
{
"tag": " whole-class interaction "
"tag": "revision"
},
{
"tag": " writing "
"tag": "whole-class interaction"
},
{
"tag": "Social mediation "
"tag": "writing"
}
],
"notes": [],
Expand Down

0 comments on commit 3c1b1f2

Please sign in to comment.