zotero/chrome/content/scaffold/templates/scrapeRIS.js

34 lines
926 B
JavaScript
Raw Normal View History

async function scrape(doc, url = doc.location.href) {
2021-12-29 01:32:56 +00:00
let DOI = url.match(/\/(10\.[^#?]+)/)[1];
// TODO adjust the URL here
let risURL = `http://citation-needed.services.springer.com/v2/references/${DOI}?format=refman&flavour=citation`;
// Z.debug(risURL)
2021-12-29 01:32:56 +00:00
// TODO adjust this
let pdfLink = doc.querySelector('#articlePDF');
// Z.debug("pdfURL: " + pdfURL);
2021-12-29 01:32:56 +00:00
let risText = await requestText(risURL);
let translator = Zotero.loadTranslator('import');
translator.setTranslator('32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7'); // RIS
translator.setString(risText);
translator.setHandler('itemDone', (_obj, item) => {
// TODO tweak some of the output here
if (pdfLink) {
item.attachments.push({
2021-12-29 01:32:56 +00:00
url: pdfLink.href,
title: 'Full Text PDF',
mimeType: 'application/pdf'
});
2021-12-29 01:32:56 +00:00
}
item.attachments.push({
title: 'Snapshot',
document: doc
});
2021-12-29 01:32:56 +00:00
item.complete();
});
2021-12-29 01:32:56 +00:00
await translator.translate();
}