No sold items

Hides sold items and removes ads on subito.it

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         No sold items
// @namespace    https://greatest.deepsurf.us/en/users/47243-liquorburn
// @version      2025-10-29
// @description  Hides sold items and removes ads on subito.it
// @author       Burn
// @copyright    2025, burn (https://openuserjs.org/users/burn)
// @license      MIT
// @match        https://www.subito.it/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let adWrapper = "ad_wrapper_";
    let soldClass = "_soldBadge__"; //"item-sold-badge";
    let parentClass = "AdItem_adItemCard__"; //"SmallCard-module_card__";

    function findElements() {
        const elements = document.querySelectorAll('[id^="'+ adWrapper +'"]');
        elements.forEach(element => {
            element.parentNode.removeChild(element);
            console.log("eliminato ad");
        });

        const soldElements = document.querySelectorAll('[class*="'+ soldClass +'"]');
        soldElements.forEach(element => {
            const parentElement = element.closest('[class*="'+ parentClass +'"]');
            if (parentElement && !parentElement.classList.contains('hidden-by-script')) {
                parentElement.style.display = 'none';
                parentElement.classList.add('hidden-by-script');
                console.log("nascosto sold item");
            }
        });
    }

    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            findElements();
        });
    });
    const config = {
        childList: true,
        subtree: true,
        attributes: true
    };
    observer.observe(document.body, config);
    findElements();

    const toggleButton = document.createElement('button');
    toggleButton.id = 'toggle-sold-items-btn';
    toggleButton.textContent = 'Mostra / nascondi venduti';
    document.body.appendChild(toggleButton);

    const style = document.createElement('style');
    style.innerText = `
      #toggle-sold-items-btn {
        position: fixed;
        bottom: 10px;
        right: 10px;
        z-index: 1000;
        background-color: #f9423a;
        color: white;
        padding: 10px 20px;
        border-radius: 4px;
        border: none;
        cursor: pointer;
        font-weight: 600;
      }
      #toggle-sold-items-btn:hover {
        background-color: #fa7b75;
        color: white;
      }
    `;
    document.head.appendChild(style);

    let hiddenItemsVisible = false;
    toggleButton.addEventListener('click', () => {
        hiddenItemsVisible = !hiddenItemsVisible;
        const hiddenElements = document.querySelectorAll('.hidden-by-script');
        hiddenElements.forEach(element => {
            element.style.display = hiddenItemsVisible ? 'block' : 'none';
        });
    });
})();