LubimyCzytać szukajka

Dodaje przyciski do wyszukiwania autora i tytułu książki na innych stronach

// ==UserScript==
// @name         LubimyCzytać szukajka
// @namespace    https://lubimyczytac.pl
// @version      1.40
// @description  Dodaje przyciski do wyszukiwania autora i tytułu książki na innych stronach
// @match        https://lubimyczytac.pl/ksiazka/*
// @grant        none
// @license      beerware
// ==/UserScript==

(function () {
    'use strict';

    // Funkcja do wyciągania tytułu i autora z treści strony
    function getTitleAndAuthorFromPage() {
        const titleElement = document.querySelector('.book__title');
        const authorElement = document.querySelector('.author');

        if (!titleElement || !authorElement) {
            console.warn('Nie udało się znaleźć tytułu lub autora.');
            return null;
        }

        const title = titleElement.textContent.trim();
        const author = authorElement.textContent.trim();
        return { title, author };
    }

    // Tworzenie i dodanie przycisków
    function injectSearchButtons() {
        const bookInfo = getTitleAndAuthorFromPage();
        if (!bookInfo) {
            console.warn('Nie udało się znaleźć tytułu i autora.');
            return;
        }

        const { title, author } = bookInfo;

        // Sprawdzenie, czy przyciski już istnieją
        if (document.querySelector('#docer-search-button') && document.querySelector('#doci-search-button') && document.querySelector('#annas-archive-button') && document.querySelector('#zlibrary-search-button') && document.querySelector('#bt4gprx-search-button') && document.querySelector('#btdig-search-button') && document.querySelector('#libgen-search-button') && document.querySelector('#google-pdf-search-button') && document.querySelector('#olx-search-button') && document.querySelector('#allegro-lokalnie-search-button')) return;

        // Tworzymy kontener dla przycisków
        const buttonContainer = document.createElement('div');
        buttonContainer.style.display = 'flex';
        buttonContainer.style.justifyContent = 'center'; 
        buttonContainer.style.alignitems = 'baseline';
        buttonContainer.style.gap = '5px'; 
        buttonContainer.style.marginBottom = '5px';
        buttonContainer.style.flexWrap = 'wrap'; 

        // Przyciski
        const buttonsData = [
            { id: 'docer-search-button', text: 'Docer', color: '#0073e6', url: `https://docer.pl/show/?q=${encodeURIComponent(title + ' ' + author)}` },
            { id: 'doci-search-button', text: 'Doci', color: '#28a745', url: `https://doci.pl/search/all/${encodeURIComponent(title + ' ' + author)}` },
            { id: 'annas-archive-button', text: 'Anna\'s Arch', color: '#3498db', url: `https://annas-archive.org/search?q=${encodeURIComponent(title + ' ' + author)}` },
            { id: 'zlibrary-search-button', text: 'Z-Library', color: '#1e90ff', url: `https://z-library.sk/s/${encodeURIComponent(title + ' ' + author)}` },
            { id: 'bt4gprx-search-button', text: 'BT4G', color: '#8e44ad', url: `https://bt4gprx.com/search?q=${encodeURIComponent(title + ' ' + author)}` },
            { id: 'btdig-search-button', text: 'BTDigg', color: '#2c3e50', url: `https://btdig.com/search?q=${encodeURIComponent(title + ' ' + author)}` },
            { id: 'libgen-search-button', text: 'LibGen', color: '#e74c3c', url: `https://libgen.is/search.php?req=${encodeURIComponent(title + ' ' + author)}` }, 
            { id: 'google-pdf-search-button', text: 'Google PDF', color: '#4285f4', url: `https://www.google.com/search?q=${encodeURIComponent(title + ' ' + author)}+pdf` }, 
            { id: 'olx-search-button', text: 'OLX', color: '#f39c12', url: `https://www.olx.pl/oferty/q-${encodeURIComponent(title + ' ' + author)}` }, 
            { id: 'allegro-lokalnie-search-button', text: 'Allegro Lok', color: '#2d8cc4', url: `https://allegrolokalnie.pl/oferty/q/${encodeURIComponent(title + ' ' + author)}` }, 
            { id: 'google-chomikuj', text: 'Google (Chomik)', color: '#f39c12', url: `https://www.google.com/search?q=site%3Ahttps%3A%2F%2Fchomikuj.pl+${encodeURIComponent(title + ' ' + author)}` },
        ];

        // Tworzymy przyciski
        buttonsData.forEach(buttonData => {
            const button = document.createElement('button');
            button.id = buttonData.id;
            button.textContent = buttonData.text;
            button.style.padding = '6px 5px'; 
            button.style.backgroundColor = buttonData.color;
            button.style.color = 'white';
            button.style.border = 'none';
            button.style.borderRadius = '0px'; 
            button.style.cursor = 'pointer';
            button.style.fontSize = '12px'; 
            button.style.minWidth = '80px'; 

            button.onclick = () => {
                window.open(buttonData.url, '_blank');
            };

            buttonContainer.appendChild(button);
        });

        // Dodanie kontenera z przyciskami na stronie
        const container = document.querySelector('.breadcrumbs'); 
        if (container) {
            container.parentNode.insertBefore(buttonContainer, container.nextSibling); 
            console.log('Dodano przyciski na stronie.');
        } else {
            console.warn('Nie udało się znaleźć miejsca na przyciski.');
        }
    }

    injectSearchButtons();
})();75