F95Zone for RDLP torrent Search button

Adds a button to search on RDLP when you are on the game thread.

// ==UserScript==
// @name        F95Zone for RDLP torrent Search button
// @namespace   Violentmonkey Scripts
// @match       https://f95zone.to/threads/*
// @grant       none
// @version     1.0
// @author      UglyOldLazyBastard
// @license WTFPL http://www.wtfpl.net/faq/
// @description Adds a button to search on RDLP when you are on the game thread.
// ==/UserScript==

(function() {
    'use strict';

      function removeSpecials(str) {
        var lower = str.toLowerCase();
        var upper = str.toUpperCase();

        var res = "";
        for(var i=0; i<lower.length; ++i) {
            if(lower[i] != upper[i] || lower[i].trim() === '')
                res += str[i];
        }
        return res;
      }



    // Function to create and add the button
    function addRDLPSearchButton() {
        // Get the text from h1.p-title-value
        const titleElement = document.querySelector('h1.p-title-value');
        if (!titleElement) return;

        let searchText = Array.from(titleElement.childNodes)
            .filter(node => node.nodeType === Node.TEXT_NODE)
            .map(node => node.textContent.trim())
            .join(' ')
            .trim();
        searchText = searchText.split("[")[0].trim();
        searchText = removeSpecials(searchText);
        console.log(searchText);

        // Create the new button
        const newButton = document.createElement('a');
        newButton.href = `https://dl.rpdl.net/torrents?search=${encodeURIComponent(searchText)}`;
        newButton.className = 'button--link button';
        newButton.innerHTML = '<span class="button-text">Search on RDLP</span>';

        // Find the .buttonGroup element
        const buttonGroup = document.querySelector('.buttonGroup');
        if (buttonGroup) {
            // Add the new button to the button group
            buttonGroup.appendChild(newButton);
        }
    }



    // Run the function when the page is fully loaded
    window.addEventListener('load', addRDLPSearchButton);
})();