Created
July 9, 2024 11:43
-
-
Save joeinnes/12dfa3c2c76f5f9433837d575ef40690 to your computer and use it in GitHub Desktop.
Add Libby Link to The StoryGraph
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
// This works as a userscript however your browser supports these (for example, I use this as an Arc Boost) | |
const MY_LIB = ''; // Add your library code here. For example, Chicago Public Library is chipublib. You can find this by opening your Libby homepage and taking the last URL segment: https://libbyapp.com/library/chipublib | |
document.addEventListener('turbo:render', addLibby); | |
function addLibby() { | |
const titleBlock = document.querySelector('.book-title-author-and-series') | |
if (titleBlock && titleBlock?.innerText && titleBlock.innerText.indexOf('• 🔗 Libby') > -1) return; | |
const title = titleBlock ? titleBlock.innerText?.split('\n')[0] : ''; | |
const target = document.querySelector('.grid .col-span-2 .text-sm:has(.browse-editions-link)') | |
const query = `https://libbyapp.com/search/${MY_LIB}/search/query-${encodeURIComponent(title)}/page-1` | |
const link = document.createElement('a') | |
link.href = query | |
link.target = '_blank'; | |
link.innerText = "• 🔗 Libby" | |
if (target) { | |
target.appendChild(link); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment