Created
November 15, 2012 15:50
-
-
Save nfreear/4079314 to your computer and use it in GitHub Desktop.
Project Gutenberg Bookmarks Javascript bookmarklet (jQuery).
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 characters
| /*! | |
| Gutenberg Bookmarks Javascript bookmarklet (jQuery). | |
| Nick Freear, 15 Nov 2012. | |
| -- | |
| http://www.gutenberg.org/catalog/world/mybookmarks | |
| -- | |
| javascript:(function(){var d=document,s=d.createElement('script');s.type='text/javascript';s.src='http://dl.dropbox.com/u/3203144/gutenberg-bookmarks.js?x='+(Math.random());d.getElementsByTagName('head')[0].appendChild(s);})(); | |
| */ | |
| (function () { | |
| var off = 1, | |
| U = 'http://www.gutenberg.org', | |
| Doc = document, | |
| WL = window.location, | |
| enc = encodeURIComponent, | |
| r = Math.round(1000 * Math.random()), | |
| DU = 'http://www.delicious.com/save?url='+ enc(WL.href + '#' + r) +'&title='+ enc(Doc.title)+'&v=6&tags=gutenberg,bookmark¬es=', | |
| opener = function () { | |
| if (! window.open(DU + '&noui=1&jump=doclose', 'deliciousuiv6', 'location=1,links=0,scrollbars=0,toolbar=0,width=710,height=660')) { | |
| location.href = DU + '&jump=yes'; | |
| } | |
| }, | |
| sc = Doc.createElement('script'); | |
| sc.type = 'text/javascript'; | |
| sc.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'; | |
| sc.onload = myCallback; | |
| Doc.getElementsByTagName('head')[0].appendChild(sc); | |
| function myCallback() { | |
| var out = [], | |
| ebooks = $('a[href *= "/ebooks/"]'); | |
| $('a[href *= "/world/readfile"]').each(function (idx, el) { | |
| var pr = $(el).attr('href'), | |
| pe = $(ebooks[idx + off]).attr('href'), | |
| tt = $(ebooks[idx + off]).text(); | |
| // Delicious: 1000 char limit. | |
| out.push({ t: tt.replace(/ by \w+/, '/'), id: pe.replace('/ebooks/', ''), r: pr.replace('/catalog/world/readfile?', '') }); | |
| //Was: out.push({ title: tt, url: U + pe, url_r: U + pr }); | |
| }); | |
| console.log(jQuery.fn.jquery); | |
| console.log(JSON.stringify(out)); | |
| DU += enc(JSON.stringify(out)); | |
| if (/Firefox/.test(navigator.userAgent)) { | |
| setTimeout(opener, 0); | |
| } else { | |
| opener(); | |
| } | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment