Skip to content

Instantly share code, notes, and snippets.

@lmmx
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmmx/9999760 to your computer and use it in GitHub Desktop.
Save lmmx/9999760 to your computer and use it in GitHub Desktop.
Citation title grabber
var titleList = [];
var paras = document.getElementsByTagName('p');
for (i=0;i<paras.length;i++) {
var thisPara = document.getElementsByTagName("p")[i].textContent;
var title = paras[i].textContent.match(/\d{4}.*?[\)]\.\s(.*?)\./);
if (title !== null) {
titleList.push(title[1]); // output is the 1st element of each array (input text = 0th)
} else {
title = paras[i].textContent.match(/\d{4}.*?[\)]\.?\s?(.*?)\./);
titleList.push(title[1]);
}
}
var selectFew = [];
for (j=0;j<titleList.length;j++) {
var resp = prompt("Keep "+titleList[j]+"?");
if (resp.match(/[yes]/gi)) { selectFew.push(titleList[j]) }
else { paras[j].remove() }
}
var selected = document.getElementsByTagName("p");
var links = [];
for (i=0;i<selected.length;i++) {
if (selected[i].textContent.indexOf("doi:") !== -1) {
doi = selected[i].textContent.match(/doi:(.*)\sRead more/)[1];
link="http://dx.doi.org/"+doi;
links.push(link);
}
else if (selected[i].textContent.indexOf("http") !== -1) {
link = selected[i].textContent.match(/(http.*)\sRead more/)[1];
links.push(link);
}
else {
link = selected[i].querySelector('a').href;
links.push(link);
}
}
var selectedTitles = [];
for (i=0;i<selected.length;i++) {
htmlitem = '<li><em><a href="'+links[i]+'">'+selected[i].textContent.match(/\d{4}.*?[\)]\.?\s?(.*?)\./)[1]+'</a></em></li>';
selectedTitles.push(htmlitem);
}
copy(selectedTitles.join(''));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment