Skip to content

Instantly share code, notes, and snippets.

@vnorby
Created November 20, 2012 07:25
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vnorby/4116565 to your computer and use it in GitHub Desktop.
Save vnorby/4116565 to your computer and use it in GitHub Desktop.
Bookmarklet to show Paul Graham's essay footnotes inline on hover
javascript:(function(e,t,n,r,i,s,o,u){if(!(i=e.jQuery)||n>i.fn.jquery||r(i)){s=t.createElement("script");s.type="text/javascript";s.src="http://ajax.googleapis.com/ajax/libs/jquery/"+n+"/jquery.min.js";s.onload=s.onreadystatechange=function(){if(!o&&(!(u=this.readyState)||u=="loaded"||u=="complete")){r((i=e.jQuery).noConflict(1),o=1);i(s).remove()}};t.documentElement.childNodes[0].appendChild(s)}})(window,document,"1.8.3",function(e,t){var n=e("font[color]").filter(function(){if(parseInt(e(this).text(),10)>0){return true}return false}).parent();var r=e("body").html();n.each(function(){var t=e(this).attr("href").replace("#","");var n=parseInt(t.replace("f",""),10);var i=new RegExp('<a name="'+t+'">([^]*?)[[]');var s=r.match(i);if(s&&s[0]){var o=e(s[0].replace("<br>","\n")).text().replace(n+"]","");o=o.replace("csell_env = 'mud';","").replace("// Begin Y! Store Generated Code","");var u=e('<div class="note" style="background:#FFFFFF;border:3px solid #000;left:0px;top:15px;width:300px;position:absolute;padding:10px;color:#000;text-decoration:none;">'+o+"</div>");e(this).parent().hover(function(){e(this).css("position","relative").append(u)},function(){u.remove()})}})})
@vnorby
Copy link
Author

vnorby commented Nov 20, 2012

This bookmarklet will take PG's essay footnotes and make them available to you upon hover over the footnote inline so you don't have to lose your place. To add to Chrome or other browsers, simply create a new bookmark but add the above string as the URL. Then when reading a PG essay, click the bookmarklet and enjoy.

@jonleung
Copy link

Thanks for making this @vnorby! I modded this to directly embed the footnote into the text for audio text to speech.

javascript:(function(e, t, n, r, i, s, o, u) {
    if (!(i = e.jQuery) || n > i.fn.jquery || r(i)) {
        s = t.createElement("script");
        s.type = "text/javascript";
        s.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + n + "/jquery.min.js";
        s.onload = s.onreadystatechange = function() {
            if (!o && (!(u = this.readyState) || u == "loaded" || u == "complete")) {
                r((i = e.jQuery).noConflict(1), o = 1);
                i(s).remove()
            }
        };
        t.documentElement.childNodes[0].appendChild(s)
    }
})(window, document, "1.8.3", function(e, t) {
    var n = e("font[color]").filter(function() {
        if (parseInt(e(this).text(), 10) > 0) {
            return true
        }
        return false
    }).parent();
    var r = e("body").html();
    n.each(function() {
        var t = e(this).attr("href").replace("#", "");
        var n = parseInt(t.replace("f", ""), 10);
        var i = new RegExp('<a name="' + t + '">([^]*?)[[]');
        var s = r.match(i);
        if (s && s[0]) {
            var o = e(s[0].replace("<br>", "\n")).text().replace(n + "]", "");
            o = o.replace("csell_env = 'mud';", "").replace("// Begin Y! Store Generated Code", "");
            var u = e('<div class="note" style="background:#FFFFFF;border:3px solid #000;left:0px;top:15px;width:300px;position:absolute;padding:10px;color:#000;text-decoration:none;">' + o + "</div>");
            e(this).parent().html("Begin Sidenote. " + o + " End Sidenote.")
        }
    })
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment