Skip to content

Instantly share code, notes, and snippets.

@bocklund

bocklund/illiad.js

Last active Aug 21, 2017
Embed
What would you like to do?
Fill a form on the ILLiad article submission page based on a user-prompted Bibtex reference
/* Submit requests to ILLiad by populating different fields from a bibtex reference*/
/* We want to do some parsing of input bibtex, files, so we'll include the*/
/* following JS code in our bookmarklet*/
/* keys are the ILLiad field names, values are the bibtex entry keys*/
var replacementDict = {
'PhotoJournalTitle' : 'JOURNAL',
'PhotoJournalTitle' : 'JOURNAL',
'PhotoJournalVolume' : 'VOLUME',
'PhotoJournalIssue' : 'NUMBER',
'PhotoJournalMonth' : 'MONTH',
'PhotoJournalYear' : 'YEAR',
'PhotoJournalInclusivePages' : 'PAGES',
'PhotoArticleAuthor' : 'AUTHOR',
'PhotoArticleTitle' : 'TITLE',
'ISSN': 'ISSN'
};
function loadScript(url, callback)
{
/* code for loading from: https://stackoverflow.com/questions/950087/how-do-i-include-a-javascript-file-in-another-javascript-file*/
/* url is the url to load*/
/* callback is my custom code to run after loading*/
/* Adding the script tag to the head as suggested before*/
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
/* Then bind the event to the callback function.*/
/* There are several events for cross browser compatibility.*/
script.onreadystatechange = callback;
script.onload = callback;
/* Fire the loading*/
head.appendChild(script);
}
var replaceValues = function() {
/* Here, do what ever you want*/
var bibJSON = doParse(bibliographyText);
for (var key in bibJSON) {
/* go through all of the replacement dict fields and populate the field*/
/* of the form with they corresponding key from the bibtex*/
if (bibJSON.hasOwnProperty(key) && key != '@comments') {
for (var field in replacementDict) {
var el = document.getElementById(field);
el.value = bibJSON[key][replacementDict[field]];
if (el.value == 'undefined') {el.value = '';}
}
}
/* finally, set the notes value to the input bibtex, for later reference*/
var el = document.getElementById('Notes');
el.value = bibliographyText;
}
};
/* get the input from the user*/
var bibliographyText = window.prompt('Enter the bibliography (bibtex format) string', '@article{...}');
/* load the script and do the replacement*/
loadScript("https://cdn.rawgit.com/mikolalysenko/bibtex-parser/7feff8a3/parse-bibtex.js", replaceValues);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.