Skip to content

Instantly share code, notes, and snippets.

@fsantini
Last active February 23, 2023 15:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fsantini/8cc6a0628befc8fa4ac24894def55835 to your computer and use it in GitHub Desktop.
Save fsantini/8cc6a0628befc8fa4ac24894def55835 to your computer and use it in GitHub Desktop.
Zotero translator for ISMRM Proceedings
{
"translatorID": "64f80311-85ec-4089-ae6d-665b535fb3b3",
"label": "ISMRM Proceedings",
"creator": "Francesco Santini",
"target": "https?://(index.*mirasmart.com/ISMRM[0-9]+/(PDFfiles/)?|cds.ismrm.org/protected/.*Presentations/abstracts/|cds.ismrm.org/protected/.*Proceedings/PDFfiles/)",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2023-02-20 15:10:57"
}
var places = {
'2016': 'Singapore',
'2017': 'Honolulu (HI, USA)',
'2018': 'Paris (France)',
'2019': 'Montreal (QC, Canada)',
'2020': 'Virtual',
'2021': 'Virtual',
'2022': 'London (UK)',
'2023': 'Toronto (ON, Canada)',
'2024': 'Singapore',
'2025': 'Honolulu (HI, USA)'
};
function detectWeb(doc, url) {
//Zotero.debug("************************ detectWeb *****************")
if (url.match(/PDFfiles/) || url.match(/abstracts/))
return "conferencePaper";
else
return "multiple";
}
function scrape(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == "x" ) return namespace; else return null;
} : null;
var item = new Zotero.Item("conferencePaper");
var procNamePath = '//div[@id="ctl00_MainContent_ViewSubmissions_divFooter"]/div';
var procNameObject = doc.evaluate(procNamePath, doc, nsResolver, XPathResult.ANY_TYPE, null);
if (procNameObject == null)
{
procNamePath = '//div[@id="ctl00_MainContent_ctl00_divFooter"]/div';
procNameObject = doc.evaluate(procNamePath, doc, nsResolver, XPathResult.ANY_TYPE, null);
}
var procNameItem = procNameObject.iterateNext();
if (procNameItem == null) // 2016 uses a different way
{
procNamePath = '//div[@class="col-lg-5 col-md-5 col-sm-5"]';
procNameObject = doc.evaluate(procNamePath, doc, nsResolver, XPathResult.ANY_TYPE, null);
procNameItem = procNameObject.iterateNext();
}
var procName = procNameItem.innerText;
var year = procName.match(/\(([0-9]+)\)/)[1];
Zotero.debug(year);
item.date = year;
item.proceedingsTitle = procName;
item.url = url;
item.place = places[year];
var titlePath = '//span[@id="ctl00_MainContent_ctl00_submissionTitle"]';
var titleObj = doc.evaluate(titlePath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
var title = "";
if (titleObj == null)
{
titlePath = '//span[@id="ctl00_MainContent_ViewSubmissions_submissionTitle"]';
titleObj = doc.evaluate(titlePath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
title = titleObj.innerText;
}
else
{
title = titleObj.innerText;
}
item.title = title;
var authPath = '//div[@id="affAuthers"]';
var authObj = doc.evaluate(authPath, doc, nsResolver, XPathResult.ANY_TYPE, null);
var authItem = authObj.iterateNext()
if (authItem == null)
{
console.log("Null authObj");
authPath = '//div[@id="ctl00_MainContent_ctl00_AuthorsAndAffiliationsBlock_divBlockContainer"]';
authObj = doc.evaluate(authPath, doc, nsResolver, XPathResult.ANY_TYPE, null);
authItem = authObj.iterateNext()
}
authItem = authItem.cloneNode(true); // clone a node with children, so we can edit it
// affiliations are in italic. remove them.
var itPath = '//i';
var itObj = doc.evaluate(itPath, authItem, nsResolver, XPathResult.ANY_TYPE, null);
while (itItem = itObj.iterateNext())
{
itItem.remove();
}
// remove the affiliation numbers which are superscript nodes
var supPath = '//SUP';
var supObj = doc.evaluate(supPath, authItem, nsResolver, XPathResult.ANY_TYPE, null);
while (supItem = supObj.iterateNext())
{
supItem.remove();
}
//Zotero.debug(authItem);
var authors = authItem.innerText.split(',');
// now authors is an array with First Name(s) Last Name. Last author has a prepended "and"
var stopAuthors = false;
authors.forEach(
function (author)
{
if (stopAuthors) return;
var authorObj = new Object();
authorObj['creatorType'] = 'author';
author = author.trim();
if (author.startsWith("and "))
{
author = author.substr("and ".length);
stopAuthors = true; //stop scanning after the author with "and". 2021 proceedings don't have a different class for affiliations
}
var authorAtom = author.split(' ');
var lastName = authorAtom[authorAtom.length - 1]; // assume last name is the last word
var firstName = authorAtom.slice(0,authorAtom.length - 1).join(' ');
authorObj['firstName'] = firstName;
authorObj['lastName'] = lastName;
item.creators.push(authorObj);
});
//Zotero.debug(item);
item.complete();
}
function doWeb(doc, url)
{
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == "x" ) return namespace; else return null;
} : null;
var urls = new Array();
var items = new Object();
if (detectWeb(doc, url) == "multiple")
{
var eachResult = '//div[@class="full search-result"]';
var resultTitle = eachResult + '/h2';
var resultLink = eachResult + '/ul/li/a';
var resultsIterator = doc.evaluate(eachResult, doc, nsResolver, XPathResult.ANY_TYPE, null);
var linkIterator = doc.evaluate(resultLink, doc, nsResolver, XPathResult.ANY_TYPE, null);
var titleIterator = doc.evaluate(resultTitle, doc, nsResolver, XPathResult.ANY_TYPE, null);
while (resultObj = resultsIterator.iterateNext())
{
//Zotero.debug(resultObj)
var link = linkIterator.iterateNext().href;
//Zotero.debug(link);
var title = titleIterator.iterateNext().innerText;
//Zotero.debug(title);
items[link] = title;
}
items = Zotero.selectItems(items);
for (var i in items)
{
urls.push(i);
}
} else
{
urls = [url];
}
//Zotero.debug(urls);
Zotero.Utilities.processDocuments(urls, scrape, function(){Zotero.done();});
Zotero.wait();
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://cds.ismrm.org/protected/17MProceedings/PDFfiles/1986.html",
"items": [
{
"itemType": "conferencePaper",
"title": "Modeling the increased inhomogeneous magnetization transfer (ihMT) signal from high amplitude, low duty cycle irradiation",
"creators": [
{
"creatorType": "author",
"firstName": "Gopal",
"lastName": "Varma"
},
{
"creatorType": "author",
"firstName": "Aaron K",
"lastName": "Grant"
},
{
"creatorType": "author",
"firstName": "Olivier M",
"lastName": "Girard"
},
{
"creatorType": "author",
"firstName": "Valentin H",
"lastName": "Prevost"
},
{
"creatorType": "author",
"firstName": "Guillaume",
"lastName": "Duhamel"
},
{
"creatorType": "author",
"firstName": "David C",
"lastName": "Alsop"
}
],
"date": "2017",
"libraryCatalog": "ISMRM Proceedings",
"place": "Honolulu (HI, USA)",
"proceedingsTitle": "Proc. Intl. Soc. Mag. Reson. Med. 25 (2017)",
"url": "https://cds.ismrm.org/protected/17MProceedings/PDFfiles/1986.html",
"attachments": [],
"tags": [],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/
@abrarfaiyaz
Copy link

Hi,
I get the following error when trying to run it from the Tool-> Developer Menu
SyntaxError: unexpected token: ':'

Any insight would be really helpful!

Bests,
Abrar F.

@fsantini
Copy link
Author

How are you trying to run it? When running it from the browser it works for me. Try saving this file in the translators directory of Zotero and import one abstract into your library.

@praveenivp
Copy link

Doesn't work lately with latest firefox ESR (102.8.0esr)

@fsantini
Copy link
Author

I just uploaded a new version which should solve some issue. Can you please try? I don't think it depends on Firefox version. Please mention which year you are trying to import. The format of the abstracts changes a bit every year.

@praveenivp
Copy link

praveenivp commented Feb 23, 2023

I tried 17M and 21M. It is not throwing any errors now. But it doesn't scrape details like title, year, etc. Thanks for the quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment