F95Zone for RDLP torrent Search button

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

Versione datata 11/11/2024. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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);
})();