F95 Utility buttons

Added a search button for Compressed, Update only, Walkthrough ....

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         F95 Utility buttons
// @namespace    http://tampermonkey.net/
// @description  Added a search button for Compressed, Update only, Walkthrough ....
// @version      2.0
// @author       GGD40727
// @match        https://f95zone.to/threads/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=f95zone.to
// @grant        GM_registerMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// @license      MIT

// ==/UserScript==


(function() {
    'use strict';

    // --- Toggle Logic ---
    let openInNewTab = GM_getValue('openInNewTab', false);

    GM_registerMenuCommand(`Toggle New Tab: ${openInNewTab ? '✅ ON' : '❌ OFF'}`, () => {
        openInNewTab = !openInNewTab;
        GM_setValue('openInNewTab', openInNewTab);
        location.reload(); 
    });

    const BUTTONS = [
        { label: 'Update', position: '43%', searchSuffix: ' Update Only' },
        { label: 'New+Compressed', position: '50%', searchSuffix: ' Compressed' },
        { label: 'Compressed', position: '57%', searchTerm: 'Compressed' },
        { label: 'Walkthrough', position: '64%', searchSuffix: ' Walkthrough' },
        { label: 'Mod', position: '71%', searchTerm: 'Mod' },
        { label: 'Cheats', position: '78%', searchSuffix: ' Cheats' }
    ];

    const SELECTORS = {
        title: 'div.p-title h1.p-title-value',
        searchInput: '.uix_searchInput',
        searchButton: 'button.button--primary.button--icon--search'
    };

    const BUTTON_STYLES = {
        position: 'fixed',
        right: '0px',
        zIndex: '9999',
        lineHeight: '30px',
        fontSize: '14px',
        cursor: 'pointer',
        padding: '5px 10px',
        border: '1px solid #444',
        borderRadius: '4px 0 0 4px',
        backgroundColor: '#2d2d2d',
        color: '#efefef'
    };

    function getGameTitle() {
        const titleElement = document.querySelector(SELECTORS.title);
        if (!titleElement) return null;
        const match = titleElement.textContent.match(/\[(.*?)\]/);
        return match ? match[1] : null;
    }

    // Helper to get Thread ID from URL for filtered searching
    function getThreadId() {
        const match = window.location.pathname.match(/\.([0-9]+)\/$/);
        return match ? match[1] : null;
    }

    function performSearch(searchTerm) {
        if (openInNewTab) {
            const threadId = getThreadId();
            // Use 't=post' and 'c[thread]' to lock search to THIS thread only
            let searchUrl = `https://f95zone.to/search/1/?q=${encodeURIComponent(searchTerm)}&t=post&o=relevance`;
            if (threadId) searchUrl += `&c[thread]=${threadId}`;
            
            window.open(searchUrl, '_blank');
        } else {
            const searchInput = document.querySelector(SELECTORS.searchInput);
            const searchButton = document.querySelector(SELECTORS.searchButton);
            if (!searchInput || !searchButton) return;

            searchInput.value = searchTerm;
            searchInput.dispatchEvent(new Event('input', { bubbles: true }));
            searchButton.click();
        }
    }

    function createButton(config, gameTitle) {
        const button = document.createElement('input');
        button.type = 'button';
        button.value = config.label;
        button.className = 'f95-quick-search-btn';

        Object.assign(button.style, BUTTON_STYLES, { top: config.position });

        // Hover effects
        button.addEventListener('mouseenter', () => button.style.backgroundColor = '#444');
        button.addEventListener('mouseleave', () => button.style.backgroundColor = '#2d2d2d');

        button.addEventListener('click', () => {
            let searchTerm = config.searchTerm || (gameTitle ? gameTitle + config.searchSuffix : null);
            if (searchTerm) performSearch(searchTerm);
            else console.warn('[F95 Script] Cannot determine search term');
        });

        return button;
    }

    function init() {
        const gameTitle = getGameTitle();
        BUTTONS.forEach(config => {
            document.body.appendChild(createButton(config, gameTitle));
        });
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
})();