RyuuGames F95Zone Search Button

Adds a button to search the game title on F95Zone from RyuuGames

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         RyuuGames F95Zone Search Button
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  Adds a button to search the game title on F95Zone from RyuuGames
// @author       FunkyJustin
// @license      MIT
// @match        https://www.ryuugames.com/*
// @grant        none
// @supportURL      https://greasyfork.org/en/scripts/497408-ryuugames-f95zone-search-button/feedback
// ==/UserScript==

(function() {
    'use strict';

    // Function to add the search button
    function addSearchButton() {
        // Get the header element with class 'td-post-title'
        let header = document.querySelector('header.td-post-title');
        if (header) {
            // Get the H1 element within the header
            let h1 = header.querySelector('h1.entry-title');
            if (h1 && !header.querySelector('.f95zone-search-button')) { // Check if the button already exists
                // Extract the game title from the H1 text
                let titleText = h1.textContent;
                let gameTitle = titleText.replace(/^\[ENG\] /, '').replace(/\s*\(RJ\d+\)\s*$/, '');

                // Create the search button
                let searchButton = document.createElement('button');
                searchButton.textContent = 'Search on F95Zone';
                searchButton.style.marginTop = '10px';
                searchButton.style.display = 'block';
                searchButton.className = 'f95zone-search-button'; // Add a class for easier identification

                // Define the search URL
                let searchUrl = 'https://f95zone.to/sam/latest_alpha/#/cat=games/page=1/search=' + encodeURIComponent(gameTitle);

                // Add event listener to the button to open the search URL in a new tab
                searchButton.addEventListener('click', function() {
                    window.open(searchUrl, '_blank');
                });

                // Insert the button after the H1 element
                h1.insertAdjacentElement('afterend', searchButton);
            }
        }
    }

    // Observe changes to the body to ensure the button is added even if content is loaded dynamically
    const observer = new MutationObserver(addSearchButton);
    observer.observe(document.body, { childList: true, subtree: true });

    // Initial call in case the content is already loaded
    addSearchButton();
})();