Last active
December 17, 2015 15:08
-
-
Save rradczewski/5629079 to your computer and use it in GitHub Desktop.
Bib(La)Tex Bookmarklet - Creates a Bib(La)Tex Entry from Site Metadata
This file contains 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 characters
if (parts = document.title.split(///\s[-|–]\s///)).length == 2 | |
title = parts[0] | |
author = parts[1] | |
else | |
title = document.title | |
author = (document.getElementsByName("author")[0])?.content || document.location.host.replace(/^((.+)\.)?([^\.]+\.[^\.]+)$/, '$3') | |
language = (document.getElementsByTagName("html")[0])?.lang || "en" | |
pad = ((num) -> if num < 10 then "0"+num else num) | |
date_part = (date) -> | |
year: date.getFullYear() | |
month: pad(date.getMonth()+1) | |
month_abbr: date.toString().substring(4, 7) | |
day: pad(date.getDate()) | |
now = date_part(new Date()) | |
modified = date_part(new Date(document.lastModified)) | |
url = document.location.href | |
modifieddate = modified.year+'-'+modified.month+'-'+modified.day | |
urldate = now.year+'-'+now.month+'-'+now.day | |
easytitle = (author+modified.year+title.replace(/[\W]/g, " ").split(/[\s]+/)[0..3].join("")).replace(/\s/g, "").toLowerCase() | |
w = window.open('', '', 'width=400,height=400,resizeable,scrollbars'); | |
w.document.write("""<pre> | |
@ONLINE{#{easytitle}, | |
title = {#{title}}, | |
author = {#{author}}, | |
language = {#{language}}, | |
month = {#{modified.month_abbr}}, | |
year = {#{modified.year}}, | |
date = {#{modifieddate}}, | |
url = {#{url}}, | |
urldate = {#{urldate}}, | |
}</pre>"""); | |
w.document.close() |
This file contains 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 characters
<a href='javascript:(function(){var h,l,k,j,o,b,c,e,g,m,a,d,n,i,f;if((g=document.title.split(/\s[-|–]\s/)).length===2){m=g[0];h=g[1]}else{m=document.title;h=((i=(document.getElementsByName("author")[0]))!=null?i.content:void 0)||document.location.host.replace(/^((.+)\.)?([^\.]+\.[^\.]+)$/,"$3")}j=((f=(document.getElementsByTagName("html")[0]))!=null?f.lang:void 0)||"en";e=(function(p){if(p<10){return"0"+p}else{return p}});l=function(p){return{year:p.getFullYear(),month:e(p.getMonth()+1),month_abbr:p.toString().substring(4,7),day:e(p.getDate())}};c=l(new Date());o=l(new Date(document.lastModified));a=document.location.href;b=o.year+"-"+o.month+"-"+o.day;d=c.year+"-"+c.month+"-"+c.day;k=(h+o.year+m.replace(/[\W]/g," ").split(/[\s]+/).slice(0,4).join("")).replace(/\s/g,"").toLowerCase();n=window.open("","","width=400,height=400,resizeable,scrollbars");n.document.write("<pre>\n@ONLINE{"+k+",\n title = {"+m+"},\n author = {"+h+"},\n language = {"+j+"},\n month = {"+o.month_abbr+"},\n year = {"+o.year+"},\n date = {"+b+"},\n url = {"+a+"},\n urldate = {"+d+"},\n}</pre>");n.document.close()}).call(this);'>Bibtexlet</a> |
This file contains 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 characters
// Generated by CoffeeScript 1.3.3 | |
(function() { | |
var author, date_part, easytitle, language, modified, modifieddate, now, pad, parts, title, url, urldate, w, _ref, _ref1; | |
if ((parts = document.title.split(/\s[-|–]\s/)).length === 2) { | |
title = parts[0]; | |
author = parts[1]; | |
} else { | |
title = document.title; | |
author = ((_ref = (document.getElementsByName("author")[0])) != null ? _ref.content : void 0) || document.location.host.replace(/^((.+)\.)?([^\.]+\.[^\.]+)$/, '$3'); | |
} | |
language = ((_ref1 = (document.getElementsByTagName("html")[0])) != null ? _ref1.lang : void 0) || "en"; | |
pad = (function(num) { | |
if (num < 10) { | |
return "0" + num; | |
} else { | |
return num; | |
} | |
}); | |
date_part = function(date) { | |
return { | |
year: date.getFullYear(), | |
month: pad(date.getMonth() + 1), | |
month_abbr: date.toString().substring(4, 7), | |
day: pad(date.getDate()) | |
}; | |
}; | |
now = date_part(new Date()); | |
modified = date_part(new Date(document.lastModified)); | |
url = document.location.href; | |
modifieddate = modified.year + '-' + modified.month + '-' + modified.day; | |
urldate = now.year + '-' + now.month + '-' + now.day; | |
easytitle = (author + modified.year + title.replace(/[\W]/g, " ").split(/[\s]+/).slice(0, 4).join("")).replace(/\s/g, "").toLowerCase(); | |
w = window.open('', '', 'width=400,height=400,resizeable,scrollbars'); | |
w.document.write("<pre>\n@ONLINE{" + easytitle + ",\n title = {" + title + "},\n author = {" + author + "},\n language = {" + language + "},\n month = {" + modified.month_abbr + "},\n year = {" + modified.year + "},\n date = {" + modifieddate + "},\n url = {" + url + "},\n urldate = {" + urldate + "},\n}</pre>"); | |
w.document.close(); | |
}).call(this); |
This file contains 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 characters
(function(){var h,l,k,j,o,b,c,e,g,m,a,d,n,i,f;if((g=document.title.split(/\s[-|–]\s/)).length===2){m=g[0];h=g[1]}else{m=document.title;h=((i=(document.getElementsByName("author")[0]))!=null?i.content:void 0)||document.location.host.replace(/^((.+)\.)?([^\.]+\.[^\.]+)$/,"$3")}j=((f=(document.getElementsByTagName("html")[0]))!=null?f.lang:void 0)||"en";e=(function(p){if(p<10){return"0"+p}else{return p}});l=function(p){return{year:p.getFullYear(),month:e(p.getMonth()+1),month_abbr:p.toString().substring(4,7),day:e(p.getDate())}};c=l(new Date());o=l(new Date(document.lastModified));a=document.location.href;b=o.year+"-"+o.month+"-"+o.day;d=c.year+"-"+c.month+"-"+c.day;k=(h+o.year+m.replace(/[\W]/g," ").split(/[\s]+/).slice(0,4).join("")).replace(/\s/g,"").toLowerCase();n=window.open("","","width=400,height=400,resizeable,scrollbars");n.document.write("<pre>\n@ONLINE{"+k+",\n title = {"+m+"},\n author = {"+h+"},\n language = {"+j+"},\n month = {"+o.month_abbr+"},\n year = {"+o.year+"},\n date = {"+b+"},\n url = {"+a+"},\n urldate = {"+d+"},\n}</pre>");n.document.close()}).call(this); |
This file contains 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 characters
#!/bin/sh | |
coffee -c bibtexlet.coffee | |
yuicompressor bibtexlet.js > bibtexlet.minified.js | |
rm bibtexlet.html | |
echo -n "<a href='javascript:" >> bibtexlet.html | |
cat bibtexlet.minified.js >> bibtexlet.html | |
echo "'>Bibtexlet</a>" >> bibtexlet.html | |
cat bibtexlet.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fiddle with Bookmarklet - Just Drag'n'Drop to Bookmarks