|
9 | 9 | "inRepository": true, |
10 | 10 | "translatorType": 4, |
11 | 11 | "browserSupport": "gcsibv", |
12 | | - "lastUpdated": "2025-12-22 18:11:41" |
| 12 | + "lastUpdated": "2026-03-09 16:01:06" |
13 | 13 | } |
14 | 14 |
|
15 | 15 | /* |
@@ -123,15 +123,36 @@ async function scrape(doc, url = doc.location.href) { |
123 | 123 | let { links } = result; |
124 | 124 | Z.debug('Links:'); |
125 | 125 | 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'); |
127 | 128 | 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 | + } |
129 | 149 | } |
130 | 150 | catch (e) { |
131 | 151 | Zotero.debug('Error while locating PDF download link: ' + e); |
132 | | - pdfURL = `/linkprocessor/v2-pdf?recordId=${recordId}&sourceRecordId=${recordId}&profileIdentifier=${opid}&intent=download&lang=en` |
133 | 152 | } |
134 | 153 |
|
| 154 | + pdfURL ||= `/linkprocessor/v2-pdf?recordId=${recordId}&sourceRecordId=${recordId}&profileIdentifier=${opid}&intent=download&lang=en`; |
| 155 | + |
135 | 156 | let risText = await requestText(risURL); |
136 | 157 | // Z.debug(risText) |
137 | 158 | let translator = Zotero.loadTranslator('import'); |
|
0 commit comments