Created
October 24, 2023 02:10
-
-
Save Mearman/cfc08f51c33591134f81c7f947e6f49c to your computer and use it in GitHub Desktop.
Revisions
-
Mearman created this gist
Oct 24, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ javascript: (function () { function fetchBibTeX(url) { fetch(url) .then((response) => response.json()) .then((data) => { const authors = data.authorships .map((author) => author.raw_author_name) .join(" and "); const title = data.title; const journal = data.primary_location.source.display_name; const year = data.publication_year; const volume = data.biblio.volume; const pages = `${data.biblio.first_page}--${data.biblio.last_page}`; const doi = data.ids.doi.split("/").pop(); const bibtex = ` @article{${authors.replace(/ /g, "")}${year}, author = {${authors}}, title = {${title}}, journal = {${journal}}, year = {${year}}, volume = {${volume}}, pages = {${pages}}, doi = {${doi}} }`; navigator.clipboard.writeText(bibtex).then( function () { alert("BibTeX entry copied to clipboard"); }, function () { prompt( "Failed to copy BibTeX entry to clipboard. You can copy it manually from here:", bibtex ); } ); }); } const currentUrl = window.location.href; const openAlexUrlPattern = /https:\/\/api\.openalex\.org\/works\/(\w+)/; const match = openAlexUrlPattern.exec(currentUrl); if (match) { fetchBibTeX(currentUrl); } else { const workId = prompt("Enter the OpenAlex Work ID:"); if (workId) { const url = `https://api.openalex.org/works/${workId}`; fetchBibTeX(url); } } })();