Skip to content

Instantly share code, notes, and snippets.

@adeel
Last active October 20, 2018 07:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adeel/d3a6ab2fff4ba39fc9f7 to your computer and use it in GitHub Desktop.
Save adeel/d3a6ab2fff4ba39fc9f7 to your computer and use it in GitHub Desktop.
arXiv citation bookmarklet
// Save the following as a bookmark:
// javascript:(function()%7Bfunction%20callback()%7B(function(%24)%7Bvar%20jQuery%3D%24%3Bvar%20authors%20%3D%20%24(%22.authors%20a%22).map(function()%20%7Breturn%20%22%5B%5B%22%20%2B%20%24.trim(%24(this).html())%20%2B%20%22%5D%5D%22%3B%7D).get().join(%22%2C%20%22)%3B%24(%22.title%20.descriptor%22).remove()%3Bvar%20title%20%3D%20%24.trim(%24(%22.title%22).html())%3Bvar%20arxivId%20%3D%20%24(%22.arxivid%20a%22).html()%3Bvar%20URL%20%3D%20location.href%3Bvar%20citation%20%3D%20%22*%20%22%20%2B%20authors%20%2B%20%22%2C%20_%22%20%2B%20title%20%2B%20%22_%2C%20%5B%22%20%2B%20arxivId%20%2B%20%22%5D(%22%20%2B%20URL%20%2B%20%22).%22%3Bwindow.prompt(%22Copy%20to%20clipboard%3A%20Ctrl%2BC%2C%20Enter%22%2C%20citation)%7D)(jQuery.noConflict(true))%7Dvar%20s%3Ddocument.createElement(%22script%22)%3Bs.src%3D%22https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fjquery%2F2.1.3%2Fjquery.min.js%22%3Bif(s.addEventListener)%7Bs.addEventListener(%22load%22%2Ccallback%2Cfalse)%7Delse%20if(s.readyState)%7Bs.onreadystatechange%3Dcallback%7Ddocument.body.appendChild(s)%3B%7D)()
function runArXivCitationBookmarklet() {
var authors = $(".authors a").map(function() {
return "[[" + $.trim($(this).html()) + "]]";
}).get().join(", ");
$(".title .descriptor").remove();
var title = $.trim($(".title").html());
var arxivId = $(".arxivid a").html();
var URL = location.href;
var citation = "* " + authors + ", _" + title + "_, [" + arxivId + "](" + URL + ").";
window.prompt("Copy to clipboard: Ctrl+C, Enter", citation);
}
(function () {
var js = document.createElement('script');
js.addEventListener('load', runArXivCitationBookmarklet);
js.src = "//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js";
document.head.appendChild(js);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment