Skip to content

Instantly share code, notes, and snippets.

@heavyimage
Created September 18, 2020 02:09
Show Gist options
  • Save heavyimage/28f6cac4e9c6b8e94ec5d8a30a1ad8be to your computer and use it in GitHub Desktop.
Save heavyimage/28f6cac4e9c6b8e94ec5d8a30a1ad8be to your computer and use it in GitHub Desktop.
// I don't know anything about javascript so this is probably v wrong
// Based on: https://github.com/dmstern/html2biblatex
javascript:"use strict";
(function(){
function copyToClipboard(text){
window.prompt("Copy to clipboard: Ctrl+C, Enter",text)
}
var title=document.title;
var url=document.URL;
var author_tag=document.querySelector("[name=author]");
var author=author_tag==null?"":author_tag.content;
var d=new Date;
var year=d.getFullYear();
var title_key=author.replace(/[^0-9a-z]/gi,"");
var citationKey=title_key+year;
var type="@Misc";
var title_tex=title.replace(/\u00e4/g,'\\"a').replace(/\u00c4/g,'\\"A').replace(/\u00f6/g,'\\"o').replace(/\u00d6/g,'\\"O').replace(/\u00fc/g,'\\"u').replace(/\u00dc/g,'\\"U').replace(/\u00DF/g,'\\"s');
var bibTexEntry=type+"{"+citationKey+",\n title = {"+title_tex+"},\n year = {"+year+"},\n"+(author?" author = {{"+author+"}},\n":"")+" howpublished = {\\url{"+url+"}},\n note = {[Online; Accesses 10-September-2020]}\n}";
copyToClipboard(bibTexEntry)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment