2022-05-12 21:49:30 +00:00
|
|
|
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`;
|
2019-08-02 10:09:36 +00:00
|
|
|
// Z.debug(risURL)
|
|
|
|
|
2021-12-29 01:32:56 +00:00
|
|
|
// TODO adjust this
|
|
|
|
let pdfLink = doc.querySelector('#articlePDF');
|
2019-08-02 10:09:36 +00:00
|
|
|
// 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) {
|
2019-08-02 10:09:36 +00:00
|
|
|
item.attachments.push({
|
2021-12-29 01:32:56 +00:00
|
|
|
url: pdfLink.href,
|
|
|
|
title: 'Full Text PDF',
|
|
|
|
mimeType: 'application/pdf'
|
2019-08-02 10:09:36 +00:00
|
|
|
});
|
2021-12-29 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
item.attachments.push({
|
|
|
|
title: 'Snapshot',
|
|
|
|
document: doc
|
2019-08-02 10:09:36 +00:00
|
|
|
});
|
2021-12-29 01:32:56 +00:00
|
|
|
|
|
|
|
item.complete();
|
2019-08-02 10:09:36 +00:00
|
|
|
});
|
2021-12-29 01:32:56 +00:00
|
|
|
await translator.translate();
|
2019-08-02 10:09:36 +00:00
|
|
|
}
|