TransFilter

Filtro che permette di scegliere, in una ricerca sul popolare sito di escort Bakeca Incontri, se escludere i trans o se visualizzare solo quelli.

Verze ze dne 29. 06. 2023. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name             TransFilter
// @version          1.2
// @license          MIT
// @description      Filtro che permette di scegliere, in una ricerca sul popolare sito di escort Bakeca Incontri, se escludere i trans o se visualizzare solo quelli.
// @match            https://*.bakecaincontrii.com/donna-cerca-uomo/
// @match            https://*.bakecaincontrii.com/donna-cerca-uomo/?*
// @grant            none
// @namespace http://your-namespace.example.com
// ==/UserScript==

(function() {
    var targetSubstrings = ["trans"];
    var breadcrumbElement = document.querySelector(".breadcrumb");
    let elementsToHide;
    var selectedFilter = localStorage.getItem('transFilter') || 'all';

    function getCards(){
        elementsToHide= document.getElementsByClassName("item-card");
    }

    setTimeout(getCards, 1500)

    var buttonContainer = document.createElement("div");
    buttonContainer.id = "button-container";
    buttonContainer.style.width = "100%";
    buttonContainer.style.display = "flex";
    buttonContainer.style.flexDirection = "column";
    buttonContainer.style.justifyContent = "center";
    buttonContainer.style.alignItems = "end";
    buttonContainer.style.position = "fixed";
    buttonContainer.style.zIndex = "10";
    breadcrumbElement.appendChild(buttonContainer);

    var hideButton = createButton("🍑 Niente trans", "hide");
    var allButton = createButton("Mostra tutto", "all");
    var showButton = createButton("Solo trans 🍌", "show");

    hideButton.addEventListener("click", function() {
        hideCardsWithSubstring(targetSubstrings);
        setActiveButton(hideButton);
        localStorage.setItem('transFilter', 'hide')
    });

    showButton.addEventListener("click", function() {
        showCardsWithSubstring(targetSubstrings);
        setActiveButton(showButton);
        localStorage.setItem('transFilter', 'show')
    });

    allButton.addEventListener("click", function() {
        showAllCards();
        setActiveButton(allButton);
        localStorage.setItem('transFilter', 'all')
    });

    function createButton(label, value) {
        var button = document.createElement("button");
        button.textContent = label;
        button.style.minWidth = "110px";
        button.style.margin = "10px";
        button.style.padding = "5px 10px";
        button.style.borderRadius = "5px";
        button.style.border = "none";
        button.style.background = "pink"

        buttonContainer.appendChild(button);

        if(selectedFilter === value) {
            setActiveButton(button)
        }

        return button;
    }

    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= "flex";
            }
        }
    }

    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= "flex";
                console.log("display block", element.textContent)
            } else {
                element.style.display = "none";
                console.log("display none", element.textContent)
            }
        }
    }

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

    function setActiveButton(activeButton) {
        var buttons = buttonContainer.querySelectorAll("button");
        buttons.forEach(function(button) {
            if (button === activeButton) {
                button.style.backgroundColor = "red";
            } else {
                button.style.backgroundColor = "pink";
            }
        });
    }
})();