Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Goodreads Book Page: Mobilism, ZLibrary, Anna
- // @namespace http://tampermonkey.net/
- // @version 1.1
- // @description Adds β π π ° buttons to Goodreads book pages using cleaned title + author. Strips series info and formats author as 'First Last'.
- // @match https://www.goodreads.com/book/show/*
- // @grant none
- // ==/UserScript==
- (function () {
- 'use strict';
- function cleanText(text) {
- return text.replace(/[ββββ]/g, '').replace(/\s+/g, ' ').trim();
- }
- function createBtn(emoji, url) {
- const a = document.createElement('a');
- a.href = url;
- a.target = '_blank';
- a.textContent = emoji;
- a.style.marginLeft = '10px';
- a.style.fontSize = '14px';
- a.style.textDecoration = 'none';
- a.style.padding = '4px 8px';
- a.style.borderRadius = '4px';
- a.style.border = '1px solid #ccc';
- return a;
- }
- function addButtonsToBookPage() {
- const titleEl = document.querySelector('h1[data-testid="bookTitle"]');
- const authorEl = document.querySelector('span.ContributorLink__name[data-testid="name"]');
- if (!titleEl || !authorEl) return;
- // Clean title (remove any parenthetical content)
- const rawTitle = titleEl.innerText.replace(/\(.*?\)/g, '').trim();
- const title = cleanText(rawTitle);
- // Clean and reformat author name (remove trailing asterisk, convert "Last, First" to "First Last" if needed)
- const rawAuthor = authorEl.innerText.replace(/\*$/, '').trim();
- const authorParts = rawAuthor.split(',').map(p => p.trim());
- const author = cleanText(authorParts.length === 2 ? `${authorParts[1]} ${authorParts[0]}` : rawAuthor);
- const searchTerm = `${title} ${author}`;
- const encodedQuoted = encodeURIComponent(`"${searchTerm}"`);
- const encodedUnquoted = encodeURIComponent(searchTerm);
- const mobilismURL = `https://forum.mobilism.org/search.php?keywords=${encodedQuoted}&sr=topics&sf=titleonly`;
- const zlibURL = `https://z-library.sk/s/${encodedUnquoted}`;
- const annaURL = `https://annas-archive.org/search?index=&page=1&q=${encodedUnquoted}&display=&ext=epub&sort=`;
- const buttonContainer = document.createElement('div');
- buttonContainer.style.marginTop = '8px';
- buttonContainer.appendChild(createBtn('β Mobilism', mobilismURL));
- buttonContainer.appendChild(createBtn('π Z Library', zlibURL));
- buttonContainer.appendChild(createBtn('π ° Annaβs Archive', annaURL));
- titleEl.appendChild(buttonContainer);
- }
- window.addEventListener('load', addButtonsToBookPage);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement