TransHider

Crea dei tasti per mostrare o nascondere gli annunci con i trans su Backeca Incontri

Versione datata 26/06/2023. Vedi la nuova versione l'ultima versione.

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

You will need to install an extension such as Tampermonkey to install this 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            TransHider
// @namespace       http://your-namespace.example.com
// @version         1.0
// @license         MIT
// @description     Crea dei tasti per mostrare o nascondere gli annunci con i trans su Backeca Incontri
// @match           https://*.bakecaincontrii.com/*
// @grant           none
// ==/UserScript==

(function() {
    var targetSubstrings = ["trans"]; // Sottostringhe da cercare (case insensitive)
    var elementsToHide = document.getElementsByClassName("item-card");
    var breadcrumbElement = document.querySelector(".breadcrumb");

    var hideRadio = createRadioButton("hide-radio", "Niente trans", "hide");
    var showRadio = createRadioButton("show-radio", "Solo trans", "show");
    var allRadio = createRadioButton("all-radio", "Mostra tutto", "all");

    breadcrumbElement.appendChild(hideRadio);
    breadcrumbElement.appendChild(showRadio);
    breadcrumbElement.appendChild(allRadio);

    hideRadio.addEventListener("change", function() {
        hideCardsWithSubstring(targetSubstrings);
    });

    showRadio.addEventListener("change", function() {
        showCardsWithSubstring(targetSubstrings);
    });

    allRadio.addEventListener("change", function() {
        showAllCards();
    });

    function createRadioButton(id, label, value) {
        var radio = document.createElement("input");
        radio.type = "radio";
        radio.name = "card-options";
        radio.id = id;
        radio.value = value;

        var radioLabel = document.createElement("label");
        radioLabel.htmlFor = id;
        radioLabel.textContent = label;

        var radioContainer = document.createElement("div");
        radioContainer.appendChild(radio);
        radioContainer.appendChild(radioLabel);

        return radioContainer;
    }

    function hideCardsWithSubstring(substrings) {
        for (var i = 0; i < elementsToHide.length; i++) {
            var element = elementsToHide[i];
            var textFields = element.querySelectorAll(".item-title, .item-description");

            var shouldHide = false;
            for (var j = 0; j < textFields.length; j++) {
                var textField = textFields[j];
                var text = textField.textContent.toLowerCase();
                for (var k = 0; k < substrings.length; k++) {
                    var substring = substrings[k].toLowerCase();
                    if (text.includes(substring)) {
                        shouldHide = true;
                        break;
                    }
                }
                if (shouldHide) {
                    break;
                }
            }

            if (shouldHide) {
                element.style.display = "none";
            } else {
                element.style.display = "block";
            }
        }
    }

    function showCardsWithSubstring(substrings) {
        for (var i = 0; i < elementsToHide.length; i++) {
            var element = elementsToHide[i];
            var textFields = element.querySelectorAll(".item-title, .item-description");

            var shouldShow = false;
            for (var j = 0; j < textFields.length; j++) {
                var textField = textFields[j];
                var text = textField.textContent.toLowerCase();
                for (var k = 0; k < substrings.length; k++) {
                    var substring = substrings[k].toLowerCase();
                    if (text.includes(substring)) {
                        shouldShow = true;
                        break;
                    }
                }
                if (shouldShow) {
                    break;
                }
            }

            if (shouldShow) {
                element.style.display = "block";
            } else {
                element.style.display = "none";
            }
        }
    }

    function showAllCards() {
        for (var i = 0; i < elementsToHide.length; i++) {
            var element = elementsToHide[i];
            element.style.display = "block";
        }
    }
})();