Last active
September 4, 2025 02:00
-
-
Save whopiyush/65e4b7b2e2e6e69353da90b640fdc753 to your computer and use it in GitHub Desktop.
Userscript to add a button to search the book on libgen to storygraph books page
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
| // ==UserScript== | |
| // @name Search Book Title on Libgen (StoryGraph) | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.5 | |
| // @description Append a "Search on Libgen" button on StoryGraph book pages | |
| // @author Piyush (https://pycz.dev) | |
| // @match https://app.thestorygraph.com/books/* | |
| // @grant none | |
| // ==/UserScript== | |
| (function () { | |
| 'use strict'; | |
| // Function to extract raw text not wrapped by tags | |
| function getRawText(element) { | |
| let rawText = ''; | |
| element.childNodes.forEach((node) => { | |
| if (node.nodeType === Node.TEXT_NODE) { | |
| rawText += node.textContent.trim(); | |
| } | |
| }); | |
| return rawText; | |
| } | |
| // Function to add the "Search on Libgen" button | |
| function addLibgenSearchButton() { | |
| // Select the element containing the book title | |
| const titleElement = document.querySelector('h3.font-serif.font-bold.text-2xl'); | |
| const titleAuthorDiv = document.querySelector('div.book-title-author-and-series'); | |
| // Check if both the title and the target div exist | |
| if (titleElement && titleAuthorDiv) { | |
| // Extract only the raw text from the title element | |
| const bookTitle = getRawText(titleElement); | |
| // Create the "Search on Libgen" button | |
| const searchButton = document.createElement('button'); | |
| searchButton.textContent = 'Search on Libgen'; | |
| // Apply the same styles as "Track progress" button | |
| searchButton.type = 'button'; | |
| searchButton.className = 'track-progress-button text-darkerGrey dark:text-lightGrey mt-2 mb-2 px-2 py-1 inline-flex secondary-btn'; | |
| // Add click event to the button | |
| searchButton.addEventListener('click', () => { | |
| const libgenURL = `https://libgen.is/search.php?req=${encodeURIComponent(bookTitle)}`; | |
| window.open(libgenURL, '_blank'); | |
| }); | |
| // Insert the button below the title-author div | |
| titleAuthorDiv.appendChild(searchButton); | |
| } | |
| } | |
| // Only execute the function on page load | |
| window.addEventListener('load', addLibgenSearchButton); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment