Advertisement
Guest User

Untitled

a guest
May 8th, 2025
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Goodreads Book Page: Mobilism, ZLibrary, Anna
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Adds β“‚ πŸ“š πŸ…° buttons to Goodreads book pages using cleaned title + author. Strips series info and formats author as 'First Last'.
  6. // @match https://www.goodreads.com/book/show/*
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. (function () {
  11. 'use strict';
  12.  
  13. function cleanText(text) {
  14. return text.replace(/[β€œβ€β€˜β€™]/g, '').replace(/\s+/g, ' ').trim();
  15. }
  16.  
  17. function createBtn(emoji, url) {
  18. const a = document.createElement('a');
  19. a.href = url;
  20. a.target = '_blank';
  21. a.textContent = emoji;
  22. a.style.marginLeft = '10px';
  23. a.style.fontSize = '14px';
  24. a.style.textDecoration = 'none';
  25. a.style.padding = '4px 8px';
  26. a.style.borderRadius = '4px';
  27. a.style.border = '1px solid #ccc';
  28. return a;
  29. }
  30.  
  31. function addButtonsToBookPage() {
  32. const titleEl = document.querySelector('h1[data-testid="bookTitle"]');
  33. const authorEl = document.querySelector('span.ContributorLink__name[data-testid="name"]');
  34. if (!titleEl || !authorEl) return;
  35.  
  36. // Clean title (remove any parenthetical content)
  37. const rawTitle = titleEl.innerText.replace(/\(.*?\)/g, '').trim();
  38. const title = cleanText(rawTitle);
  39.  
  40. // Clean and reformat author name (remove trailing asterisk, convert "Last, First" to "First Last" if needed)
  41. const rawAuthor = authorEl.innerText.replace(/\*$/, '').trim();
  42. const authorParts = rawAuthor.split(',').map(p => p.trim());
  43. const author = cleanText(authorParts.length === 2 ? `${authorParts[1]} ${authorParts[0]}` : rawAuthor);
  44.  
  45. const searchTerm = `${title} ${author}`;
  46. const encodedQuoted = encodeURIComponent(`"${searchTerm}"`);
  47. const encodedUnquoted = encodeURIComponent(searchTerm);
  48.  
  49. const mobilismURL = `https://forum.mobilism.org/search.php?keywords=${encodedQuoted}&sr=topics&sf=titleonly`;
  50. const zlibURL = `https://z-library.sk/s/${encodedUnquoted}`;
  51. const annaURL = `https://annas-archive.org/search?index=&page=1&q=${encodedUnquoted}&display=&ext=epub&sort=`;
  52.  
  53. const buttonContainer = document.createElement('div');
  54. buttonContainer.style.marginTop = '8px';
  55.  
  56. buttonContainer.appendChild(createBtn('β“‚ Mobilism', mobilismURL));
  57. buttonContainer.appendChild(createBtn('πŸ“š Z Library', zlibURL));
  58. buttonContainer.appendChild(createBtn('πŸ…° Anna’s Archive', annaURL));
  59.  
  60. titleEl.appendChild(buttonContainer);
  61. }
  62.  
  63. window.addEventListener('load', addButtonsToBookPage);
  64. })();
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement