Skip to content

Instantly share code, notes, and snippets.

@MignonBelongie
Created January 4, 2022 03:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MignonBelongie/02019888af8a44811850458d891350e2 to your computer and use it in GitHub Desktop.
Save MignonBelongie/02019888af8a44811850458d891350e2 to your computer and use it in GitHub Desktop.
Bookmarklet for Open Library that shows English titles and covers, when available, in an author's list of works
javascript: (() => { document.querySelectorAll('#searchResults li.searchResultItem').forEach(el => { a = el.querySelector('.resultTitle a'); u = a.getAttribute('href').split('?')[0]; fetch(u + '/editions.json/').then(r => r.json()).then((j) => { ees = j.entries.filter(e => e.languages && e.languages[0].key == '/languages/eng'); ees2 = ees.filter(e => e.covers); ee = ees2.length? ees2[0] : ees.length? ees[0] : 0; if (ee) { el.querySelector('.resultTitle a').innerHTML = ee.title; if (ee.covers && ee.covers.length) { i = `//covers.openlibrary.org/b/id/${ee.covers[0]}-M.jpg`; el.querySelector('img').setAttribute('src', i) } } }) }) })();
@MignonBelongie
Copy link
Author

For other languages, replace /eng with the appropriate language code.

@BrittanyBunk
Copy link

thanks for making this @MignonBelongie. I really like it. It was something I thought about before and wrote about in internetarchive/openlibrary#2601.

I want to add to this, so I created this github issue: internetarchive/openlibrary#6032 that hopefully adds onto the push for internationalization of the open library and takes your work to the next level by having permanence on the open library. Maybe you can use the bookmarklet to translate the titles, so you can import it to the open library website when you fill it in for the works page.

@tfmorris
Copy link

tfmorris commented Oct 5, 2022

This fails if there are orphaned editions, e.g. https://openlibrary.org/books/OL16888076M/M%C3%A9moires_sur_la_R%C3%A9volution_fran%C3%A7aise for author https://openlibrary.org/authors/OL2404578A/Fran%C3%A7ois-Claude-Amour_marquis_de_Bouill%C3%A9

It might be worth adding a couple of words about how to use this -- and perhaps copy some of the description from the page that links here: https://openlibrary.org/developers/bookmarklets

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