Skip to content

Commit a67e38c

Browse files
committed
EBSCO Discovery Layer: Resolve PDF from "custom links"
Via web translation. https://forums.zotero.org/discussion/129776/not-grabbing-pdf-from-ebsco-psychinfo
1 parent 9b866be commit a67e38c

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

EBSCO Discovery Layer.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"inRepository": true,
1010
"translatorType": 4,
1111
"browserSupport": "gcsibv",
12-
"lastUpdated": "2025-12-22 18:11:41"
12+
"lastUpdated": "2026-03-09 16:01:06"
1313
}
1414

1515
/*
@@ -123,15 +123,36 @@ async function scrape(doc, url = doc.location.href) {
123123
let { links } = result;
124124
Z.debug('Links:');
125125
Z.debug(links);
126-
let downloadLink = links['v2-downloadLinks']?.find(link => link.type === 'pdf');
126+
127+
let downloadLink = links?.['v2-downloadLinks']?.find(link => link.type === 'pdf');
127128
if (!downloadLink) downloadLink = links.downloadLinks.find(link => link.type === 'pdf');
128-
pdfURL = downloadLink.url;
129+
130+
let externalLink = links?.['v2-fullTextAndCustomLinks']?.find(link => link.category === 'fullText');
131+
132+
if (downloadLink) {
133+
pdfURL = downloadLink.url;
134+
Zotero.debug('Trying v2-downloadLinks[type == pdf]: ' + downloadLink.url);
135+
}
136+
else if (externalLink) {
137+
Zotero.debug('Trying v2-fullTextAndCustomLinks[category == fullText] via web translation: ' + externalLink.url);
138+
let translate = Zotero.loadTranslator('web');
139+
let externalDoc = await requestDocument(externalLink.url);
140+
translate.setDocument(externalDoc);
141+
translate.setHandler('translators', () => {});
142+
translate.setHandler('itemDone', (_obj, item) => {
143+
pdfURL = item.attachments?.[0]?.url;
144+
});
145+
translate.setHandler('error', () => {});
146+
translate.setTranslator(await translate.getTranslators());
147+
await translate.translate();
148+
}
129149
}
130150
catch (e) {
131151
Zotero.debug('Error while locating PDF download link: ' + e);
132-
pdfURL = `/linkprocessor/v2-pdf?recordId=${recordId}&sourceRecordId=${recordId}&profileIdentifier=${opid}&intent=download&lang=en`
133152
}
134153

154+
pdfURL ||= `/linkprocessor/v2-pdf?recordId=${recordId}&sourceRecordId=${recordId}&profileIdentifier=${opid}&intent=download&lang=en`;
155+
135156
let risText = await requestText(risURL);
136157
// Z.debug(risText)
137158
let translator = Zotero.loadTranslator('import');

0 commit comments

Comments
 (0)