Search Fakku Doujin with Schale Network Mirrors

Extracts title and searches on Schale Network mirrors (NiyaNiya, Seia, Shupogaki, Hoshino). Marks Koharu as inactive in red color.

// ==UserScript==
// @name         Search Fakku Doujin with Schale Network Mirrors
// @namespace    http://tampermonkey.net/
// @version      1.05.0
// @description  Extracts title and searches on Schale Network mirrors (NiyaNiya, Seia, Shupogaki, Hoshino). Marks Koharu as inactive in red color.
// @author       FunkyJustin
// @match        https://www.fakku.net/hentai/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to create and insert search buttons
    function addSearchButtons() {
        const titleElement = document.querySelector('h1[class^="block col-span-full"]');

        if (titleElement) {
            const title = titleElement.innerText;

            // Add buttons for all mirrors
            createButton('Search with Koharu (Inactive)', title, 'https://koharu.to/?s=', 'koharu-search-button', titleElement, '#FF0000');  // Red color for inactive Koharu
            createButton('Search with NiyaNiya', title, 'https://niyaniya.moe/?s=', 'niyaniya-search-button', titleElement);
            createButton('Search with Seia', title, 'https://seia.to/?s=', 'seia-search-button', titleElement);
            createButton('Search with Shupogaki', title, 'https://shupogaki.moe/?s=', 'shupogaki-search-button', titleElement);
            createButton('Search with Hoshino', title, 'https://hoshino.one/?s=', 'hoshino-search-button', titleElement);
        } else {
            console.error("Title element not found. Buttons could not be added.");
        }
    }

    // Helper function to create and insert a button
    function createButton(buttonText, title, baseUrl, className, insertAfterElement, bgColor = '#4CAF50') {
        const button = document.createElement('button');
        button.innerText = buttonText;
        button.className = className;
        button.style.padding = '10px';
        button.style.fontSize = '16px';
        button.style.marginTop = '10px';
        button.style.marginLeft = '5px';
        button.style.backgroundColor = bgColor;
        button.style.color = 'white';
        button.style.border = 'none';
        button.style.borderRadius = '5px';
        button.style.cursor = 'pointer';

        // When the button is clicked, open a new tab with the search URL
        button.onclick = function() {
            const searchUrl = `${baseUrl}${encodeURIComponent(title)}`;
            window.open(searchUrl, '_blank');
        };

        // Insert the button after the h1 element
        insertAfterElement.parentNode.insertBefore(button, insertAfterElement.nextSibling);
    }

    // Wait for the page to fully load before attempting to add the buttons
    window.addEventListener('load', addSearchButtons);
})();